TAgroup5 commited on
Commit
08acf50
·
verified ·
1 Parent(s): 72fcc70

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -4
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
- # Download NLTK resources
13
- nltk.download('punkt', download_dir='/root/nltk_data')
14
- nltk.download('stopwords', download_dir='/root/nltk_data')
15
- nltk.download('wordnet', download_dir='/root/nltk_data')
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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)