kritsadaK commited on
Commit
a881000
·
1 Parent(s): c28b870
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -13,9 +13,12 @@ from nltk.tokenize import word_tokenize
13
  from nltk.corpus import stopwords
14
  from nltk.stem import WordNetLemmatizer
15
 
16
- import nltk
17
  nltk.data.path.append('/Users/kritsadakruapat/Desktop/Political-Fake-News-Detector-NLP/Fake_News_Detection/nltk_data')
18
 
 
 
 
19
  # Preprocessing helper functions
20
 
21
  # 1. Remove punctuation
@@ -130,7 +133,6 @@ def predict_with_threshold(text):
130
  st.write(f"⚠️ Potential Fake News Probability: {fake_prob:.2f}%")
131
  st.write("The news article is likely Real.")
132
 
133
-
134
  # Analyze a news article from the given URL
135
  if url:
136
  with st.spinner("Scraping the text..."):
@@ -148,4 +150,3 @@ if url:
148
 
149
  # Preprocess and predict
150
  predict_with_threshold(scraped_text)
151
-
 
13
  from nltk.corpus import stopwords
14
  from nltk.stem import WordNetLemmatizer
15
 
16
+ # Ensure NLTK resources are available by dynamically downloading if necessary
17
  nltk.data.path.append('/Users/kritsadakruapat/Desktop/Political-Fake-News-Detector-NLP/Fake_News_Detection/nltk_data')
18
 
19
+ # Download the stopwords if not already present
20
+ nltk.download('stopwords', download_dir='/Users/kritsadakruapat/Desktop/Political-Fake-News-Detector-NLP/Fake_News_Detection/nltk_data')
21
+
22
  # Preprocessing helper functions
23
 
24
  # 1. Remove punctuation
 
133
  st.write(f"⚠️ Potential Fake News Probability: {fake_prob:.2f}%")
134
  st.write("The news article is likely Real.")
135
 
 
136
  # Analyze a news article from the given URL
137
  if url:
138
  with st.spinner("Scraping the text..."):
 
150
 
151
  # Preprocess and predict
152
  predict_with_threshold(scraped_text)