RAHULJUNEJA33 commited on
Commit
baefe99
Β·
verified Β·
1 Parent(s): a9a3c01

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -14,7 +14,11 @@ os.makedirs(NLTK_DATA_PATH, exist_ok=True)
14
  nltk.data.path.append(NLTK_DATA_PATH)
15
 
16
  # Ensure punkt is downloaded
17
- nltk.download('punkt', download_dir=NLTK_DATA_PATH)
 
 
 
 
18
 
19
  # Streamlit App Configuration
20
  st.set_page_config(page_title="πŸ“Š Financial Report Sentiment Analyzer", layout="wide")
@@ -87,9 +91,13 @@ if uploaded_file:
87
 
88
  # βœ… Extract Sentences Matching Financial Keywords
89
  def extract_sentences(text, keywords):
90
- sentences = sent_tokenize(text)
91
- pattern = re.compile(r'\b(' + '|'.join(map(re.escape, keywords)) + r')\b', re.IGNORECASE)
92
- return [s for s in sentences if pattern.search(s)]
 
 
 
 
93
 
94
  # βœ… Analyze Sentiment for a Specific Financial Category
95
  def analyze_category(text, category_name, keywords):
 
14
  nltk.data.path.append(NLTK_DATA_PATH)
15
 
16
  # Ensure punkt is downloaded
17
+ try:
18
+ nltk.data.find('tokenizers/punkt')
19
+ except LookupError:
20
+ print("Downloading punkt tokenizer...")
21
+ nltk.download('punkt', download_dir=NLTK_DATA_PATH)
22
 
23
  # Streamlit App Configuration
24
  st.set_page_config(page_title="πŸ“Š Financial Report Sentiment Analyzer", layout="wide")
 
91
 
92
  # βœ… Extract Sentences Matching Financial Keywords
93
  def extract_sentences(text, keywords):
94
+ try:
95
+ sentences = sent_tokenize(text)
96
+ pattern = re.compile(r'\b(' + '|'.join(map(re.escape, keywords)) + r')\b', re.IGNORECASE)
97
+ return [s for s in sentences if pattern.search(s)]
98
+ except Exception as e:
99
+ st.error(f"❌ Error in sentence tokenization: {e}")
100
+ return []
101
 
102
  # βœ… Analyze Sentiment for a Specific Financial Category
103
  def analyze_category(text, category_name, keywords):