Update app.py
Browse files
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 |
-
|
|
|
|
|
|
|
|
|
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 |
-
|
91 |
-
|
92 |
-
|
|
|
|
|
|
|
|
|
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):
|