Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,16 +8,37 @@ from nltk.tokenize import word_tokenize
|
|
8 |
from nltk.corpus import stopwords
|
9 |
from nltk.stem import WordNetLemmatizer
|
10 |
import nltk
|
|
|
11 |
|
12 |
-
#
|
13 |
-
|
14 |
-
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
# Initialize lemmatizer and stopwords
|
18 |
lemmatizer = WordNetLemmatizer()
|
19 |
stop_words = set(stopwords.words('english'))
|
20 |
|
|
|
|
|
21 |
# Load fine-tuned model and tokenizer (adjust the model name)
|
22 |
model_name = "TAgroup5/news-classification-model" # Replace with the correct model name
|
23 |
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
|
|
8 |
from nltk.corpus import stopwords
|
9 |
from nltk.stem import WordNetLemmatizer
|
10 |
import nltk
|
11 |
+
import os
|
12 |
|
13 |
+
# Specify the directory for nltk_data
|
14 |
+
nltk_data_dir = '/root/nltk_data'
|
15 |
+
|
16 |
+
# Ensure the directory exists
|
17 |
+
if not os.path.exists(nltk_data_dir):
|
18 |
+
os.makedirs(nltk_data_dir)
|
19 |
+
|
20 |
+
# Set the NLTK data path explicitly
|
21 |
+
nltk.data.path.append(nltk_data_dir)
|
22 |
+
|
23 |
+
# Try downloading required NLTK resources
|
24 |
+
try:
|
25 |
+
nltk.download('punkt', download_dir=nltk_data_dir)
|
26 |
+
nltk.download('stopwords', download_dir=nltk_data_dir)
|
27 |
+
nltk.download('wordnet', download_dir=nltk_data_dir)
|
28 |
+
except Exception as e:
|
29 |
+
print(f"Error while downloading NLTK resources: {e}")
|
30 |
+
|
31 |
+
# Proceed with your application code
|
32 |
+
from nltk.tokenize import word_tokenize
|
33 |
+
from nltk.corpus import stopwords
|
34 |
+
from nltk.stem import WordNetLemmatizer
|
35 |
|
36 |
# Initialize lemmatizer and stopwords
|
37 |
lemmatizer = WordNetLemmatizer()
|
38 |
stop_words = set(stopwords.words('english'))
|
39 |
|
40 |
+
|
41 |
+
|
42 |
# Load fine-tuned model and tokenizer (adjust the model name)
|
43 |
model_name = "TAgroup5/news-classification-model" # Replace with the correct model name
|
44 |
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|