Spaces:
Sleeping
Sleeping
Update app/main.py
Browse files- app/main.py +17 -4
app/main.py
CHANGED
@@ -15,19 +15,32 @@ from langchain_community.embeddings import HuggingFaceBgeEmbeddings
|
|
15 |
import nltk # Importing NLTK
|
16 |
import time
|
17 |
|
18 |
-
#
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
nltk.data.path.append(nltk_data_path)
|
21 |
|
22 |
# Ensure the directory exists
|
23 |
-
|
24 |
-
os.makedirs(nltk_data_path)
|
|
|
|
|
|
|
25 |
|
26 |
# Download required NLTK resources
|
27 |
try:
|
28 |
nltk.download('punkt', download_dir=nltk_data_path)
|
|
|
29 |
except Exception as e:
|
30 |
print(f"Error downloading NLTK resources: {e}")
|
|
|
31 |
|
32 |
def clean_response(response):
|
33 |
# Remove any leading/trailing whitespace, including newlines
|
|
|
15 |
import nltk # Importing NLTK
|
16 |
import time
|
17 |
|
18 |
+
# Set writable paths for cache and data
|
19 |
+
cache_dir = '/tmp'
|
20 |
+
nltk_data_path = os.path.join(cache_dir, 'nltk_data')
|
21 |
+
|
22 |
+
# Configure NLTK and other library paths
|
23 |
+
os.environ['TRANSFORMERS_CACHE'] = os.path.join(cache_dir, 'transformers_cache')
|
24 |
+
os.environ['HF_HOME'] = os.path.join(cache_dir, 'huggingface')
|
25 |
+
os.environ['XDG_CACHE_HOME'] = cache_dir
|
26 |
+
|
27 |
+
# Add NLTK data path
|
28 |
nltk.data.path.append(nltk_data_path)
|
29 |
|
30 |
# Ensure the directory exists
|
31 |
+
try:
|
32 |
+
os.makedirs(nltk_data_path, exist_ok=True)
|
33 |
+
except OSError as e:
|
34 |
+
print(f"Error creating directory {nltk_data_path}: {e}")
|
35 |
+
raise
|
36 |
|
37 |
# Download required NLTK resources
|
38 |
try:
|
39 |
nltk.download('punkt', download_dir=nltk_data_path)
|
40 |
+
print("NLTK 'punkt' resource downloaded successfully.")
|
41 |
except Exception as e:
|
42 |
print(f"Error downloading NLTK resources: {e}")
|
43 |
+
raise
|
44 |
|
45 |
def clean_response(response):
|
46 |
# Remove any leading/trailing whitespace, including newlines
|