Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,7 @@ def analyze_financial_news():
|
|
7 |
|
8 |
# Load the text classification model pipeline
|
9 |
classification = pipeline("text-classification", model="nickmuchi/finbert-tone-finetuned-finance-topic-classification", token=access+token)
|
|
|
10 |
|
11 |
st.set_page_config(page_title="Financial News Analysis", page_icon="♕")
|
12 |
|
@@ -24,11 +25,25 @@ def analyze_financial_news():
|
|
24 |
# Perform text classification on the input text
|
25 |
results = classification(text)
|
26 |
|
27 |
-
#
|
28 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
29 |
|
30 |
def main():
|
31 |
analyze_financial_news()
|
32 |
|
33 |
if __name__ == "__main__":
|
34 |
main()
|
|
|
|
7 |
|
8 |
# Load the text classification model pipeline
|
9 |
classification = pipeline("text-classification", model="nickmuchi/finbert-tone-finetuned-finance-topic-classification", token=access+token)
|
10 |
+
sentiment_analysis = pipeline("sentiment-analysis")
|
11 |
|
12 |
st.set_page_config(page_title="Financial News Analysis", page_icon="♕")
|
13 |
|
|
|
25 |
# Perform text classification on the input text
|
26 |
results = classification(text)
|
27 |
|
28 |
+
# Filter only the news related to "Energy | Oil"
|
29 |
+
energy_oil_news = [news for news in results if news["label"] == "Energy | Oil"]
|
30 |
+
|
31 |
+
if energy_oil_news:
|
32 |
+
# If there are news related to "Energy | Oil", perform sentiment analysis for each news
|
33 |
+
for news in energy_oil_news:
|
34 |
+
sentiment_results = sentiment_analysis(news["sequence"])[0]
|
35 |
+
|
36 |
+
# Display the sentiment analysis result for each news
|
37 |
+
st.write("Original Text:", news["sequence"])
|
38 |
+
st.write("Sentiment:", sentiment_results["label"])
|
39 |
+
st.write("Sentiment Score:", sentiment_results["score"])
|
40 |
+
st.write("---")
|
41 |
+
else:
|
42 |
+
st.write("No news relevant to Energy | Oil.")
|
43 |
|
44 |
def main():
|
45 |
analyze_financial_news()
|
46 |
|
47 |
if __name__ == "__main__":
|
48 |
main()
|
49 |
+
|