Ryan commited on
Commit
fe68698
·
1 Parent(s): 8f89b6a
Files changed (1) hide show
  1. app.py +30 -0
app.py CHANGED
@@ -1,6 +1,33 @@
1
  import gradio as gr
2
  from ui.dataset_input import create_dataset_input, load_example_dataset
3
  from ui.analysis_screen import create_analysis_screen, process_analysis_request
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
 
5
  def create_app():
6
  """
@@ -81,5 +108,8 @@ def create_app():
81
  return app
82
 
83
  if __name__ == "__main__":
 
 
 
84
  app = create_app()
85
  app.launch()
 
1
  import gradio as gr
2
  from ui.dataset_input import create_dataset_input, load_example_dataset
3
  from ui.analysis_screen import create_analysis_screen, process_analysis_request
4
+ import nltk
5
+ import os
6
+
7
+ # Download necessary NLTK data packages
8
+ def download_nltk_resources():
9
+ """Download required NLTK resources if not already downloaded"""
10
+ try:
11
+ # Create nltk_data directory in the user's home directory if it doesn't exist
12
+ nltk_data_path = os.path.expanduser("~/nltk_data")
13
+ os.makedirs(nltk_data_path, exist_ok=True)
14
+
15
+ # Add this path to NLTK's data path
16
+ nltk.data.path.append(nltk_data_path)
17
+
18
+ # Download required resources
19
+ resources = ['punkt', 'wordnet', 'stopwords']
20
+ for resource in resources:
21
+ try:
22
+ nltk.data.find(f'tokenizers/{resource}')
23
+ print(f"Resource {resource} already downloaded")
24
+ except LookupError:
25
+ print(f"Downloading {resource}...")
26
+ nltk.download(resource, quiet=True)
27
+
28
+ print("NLTK resources check completed")
29
+ except Exception as e:
30
+ print(f"Error downloading NLTK resources: {e}")
31
 
32
  def create_app():
33
  """
 
108
  return app
109
 
110
  if __name__ == "__main__":
111
+ # Download required NLTK resources before launching the app
112
+ download_nltk_resources()
113
+
114
  app = create_app()
115
  app.launch()