DrishtiSharma commited on
Commit
6a9fa88
·
verified ·
1 Parent(s): 4a08170

Update interim/app.py

Browse files
Files changed (1) hide show
  1. interim/app.py +10 -6
interim/app.py CHANGED
@@ -6,19 +6,23 @@ import time
6
  import streamlit as st
7
  import nltk
8
  import tempfile
 
 
 
 
 
9
 
10
  # Set up temporary directory for NLTK resources
11
  nltk_data_path = os.path.join(tempfile.gettempdir(), "nltk_data")
12
  os.makedirs(nltk_data_path, exist_ok=True)
13
- nltk.data.path = [nltk_data_path] # Force NLTK to use only the temp directory
14
 
15
- # Force clean download of 'punkt'
16
  try:
17
- print("Ensuring NLTK 'punkt' resource is downloaded...")
18
- if not os.path.exists(os.path.join(nltk_data_path, "tokenizers/punkt")):
19
- nltk.download("punkt", download_dir=nltk_data_path)
20
  except Exception as e:
21
- print(f"Error downloading NLTK 'punkt': {e}")
22
  raise e
23
 
24
  sys.path.append(os.path.abspath("."))
 
6
  import streamlit as st
7
  import nltk
8
  import tempfile
9
+ import subprocess
10
+
11
+ # Pin NLTK to version 3.9.1
12
+ REQUIRED_NLTK_VERSION = "3.9.1"
13
+ subprocess.run([sys.executable, "-m", "pip", "install", f"nltk=={REQUIRED_NLTK_VERSION}"])
14
 
15
  # Set up temporary directory for NLTK resources
16
  nltk_data_path = os.path.join(tempfile.gettempdir(), "nltk_data")
17
  os.makedirs(nltk_data_path, exist_ok=True)
18
+ nltk.data.path.append(nltk_data_path)
19
 
20
+ # Download 'punkt_tab' for compatibility
21
  try:
22
+ print("Ensuring NLTK 'punkt_tab' resource is downloaded...")
23
+ nltk.download("punkt_tab", download_dir=nltk_data_path)
 
24
  except Exception as e:
25
+ print(f"Error downloading NLTK 'punkt_tab': {e}")
26
  raise e
27
 
28
  sys.path.append(os.path.abspath("."))