j-higgins commited on
Commit
67de2cb
·
unverified ·
1 Parent(s): f792c47

Update app.py

Browse files

Modified for Docker + JupyterLab on HuggingFace Spaces

Files changed (1) hide show
  1. app.py +35 -17
app.py CHANGED
@@ -22,7 +22,7 @@ server = app.server
22
 
23
  # Reference absolute file path
24
  BASE_DIR = os.path.dirname(os.path.abspath(__file__))
25
- CATEGORIES_FILE = os.path.join(BASE_DIR, 'google_categories(v2).txt')
26
 
27
  # Configuration for GLiNER integration
28
  custom_spacy_config = {
@@ -222,17 +222,17 @@ def batch_process_keywords(keywords, batch_size=8):
222
  app.layout = dbc.Container([
223
  dcc.Store(id='models-loaded', data=False),
224
  dbc.NavbarSimple(
225
- children=[
226
- dbc.NavItem(dbc.NavLink("About", href="#about")),
227
- dbc.NavItem(dbc.NavLink("Contact", href="#contact")),
228
- ],
229
- brand="KeyIntentNER-T",
230
- brand_href="https://github.com/jeredhiggins/KeyIntentNER-T",
231
- color="#151515",
232
- dark=True,
233
- brand_style={"background": "linear-gradient(to right, #ff7e5f, #feb47b)", "-webkit-background-clip": "text", "color": "transparent", "textShadow": "0 0 1px #ffffff, 0 0 3px #ff7e5f, 0 0 5px #ff7e5f"},
234
- ),
235
-
236
  dbc.Row(dbc.Col(html.H1('Keyword Intent, Named Entity Recognition (NER), & Google Topic Modeling Dashboard', className='text-center text-light mb-4 mt-4'))),
237
 
238
  dbc.Row([
@@ -355,9 +355,27 @@ app.layout = dbc.Container([
355
  ], width=12)
356
  ], className="mt-4 mb-4"),
357
 
358
- # Hidden divs for smooth scrolling
359
- html.Div(id='dummy-input', style={'display': 'none'}),
360
- html.Div(id='dummy-output', style={'display': 'none'}),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
361
 
362
  ], fluid=True)
363
 
@@ -506,6 +524,6 @@ def download_csv(n_clicks, processed_data):
506
  csv_string = df.to_csv(index=False, encoding='utf-8')
507
  return dict(content=csv_string, filename="KeyIntentNER-T_keyword_analysis.csv")
508
 
 
509
  if __name__ == "__main__":
510
- port = int(os.environ.get("PORT", 10000))
511
- app.run_server(debug=False, host='0.0.0.0', port=port)
 
22
 
23
  # Reference absolute file path
24
  BASE_DIR = os.path.dirname(os.path.abspath(__file__))
25
+ CATEGORIES_FILE = os.path.join(BASE_DIR, 'google_categories.txt')
26
 
27
  # Configuration for GLiNER integration
28
  custom_spacy_config = {
 
222
  app.layout = dbc.Container([
223
  dcc.Store(id='models-loaded', data=False),
224
  dbc.NavbarSimple(
225
+ children=[
226
+ dbc.NavItem(dbc.NavLink("About", href="#about", external_link=True)),
227
+ dbc.NavItem(dbc.NavLink("Contact", href="#contact", external_link=True)),
228
+ ],
229
+ brand="KeyIntentNER-T",
230
+ brand_href="https://github.com/jeredhiggins/KeyIntentNER-T",
231
+ color="#151515",
232
+ dark=True,
233
+ brand_style={"background": "linear-gradient(to right, #ff7e5f, #feb47b)", "-webkit-background-clip": "text", "color": "transparent", "textShadow": "0 0 1px #ffffff, 0 0 3px #ff7e5f, 0 0 5px #ff7e5f"},
234
+ ),
235
+
236
  dbc.Row(dbc.Col(html.H1('Keyword Intent, Named Entity Recognition (NER), & Google Topic Modeling Dashboard', className='text-center text-light mb-4 mt-4'))),
237
 
238
  dbc.Row([
 
355
  ], width=12)
356
  ], className="mt-4 mb-4"),
357
 
358
+ # JS for smooth scrolling
359
+ html.Div([
360
+ html.Script('''
361
+ document.addEventListener("DOMContentLoaded", function() {
362
+ var links = document.querySelectorAll("a[href^='#']");
363
+ links.forEach(function(link) {
364
+ link.addEventListener("click", function(e) {
365
+ e.preventDefault();
366
+ var targetId = this.getAttribute("href").substring(1);
367
+ var targetElement = document.getElementById(targetId);
368
+ if (targetElement) {
369
+ targetElement.scrollIntoView({
370
+ behavior: "smooth",
371
+ block: "start"
372
+ });
373
+ }
374
+ });
375
+ });
376
+ });
377
+ ''')
378
+ ]),
379
 
380
  ], fluid=True)
381
 
 
524
  csv_string = df.to_csv(index=False, encoding='utf-8')
525
  return dict(content=csv_string, filename="KeyIntentNER-T_keyword_analysis.csv")
526
 
527
+ # Modified the server run command for HuggingFace Spaces
528
  if __name__ == "__main__":
529
+ app.run_server(debug=False, host="0.0.0.0", port=7860)