JoanParanoid commited on
Commit
076e629
·
verified ·
1 Parent(s): 10ed7ab

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -11
app.py CHANGED
@@ -23,18 +23,24 @@ def analyze_financial_news():
23
 
24
  if analyze_clicked:
25
  # Perform text classification on the input text
26
- results = classification(text)[0]
27
-
28
- # Check if the classification is "Energy | Oil"
29
- if results["label"] == "Energy | Oil":
30
- # If the news is related to Energy | Oil, perform sentiment analysis
31
- sentiment_results = sentiment_analysis(text)[0]
32
-
33
- # Display the sentiment analysis result
34
- st.write("Sentiment:", sentiment_results["label"])
35
- st.write("Sentiment Score:", sentiment_results["score"])
 
 
 
 
 
 
36
  else:
37
- st.write("The provided news is not relevant to Energy | Oil.")
38
 
39
  def main():
40
  analyze_financial_news()
 
23
 
24
  if analyze_clicked:
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
+ text = news["sequence"]
35
+ sentiment_results = sentiment_analysis(text)[0]
36
+
37
+ # Display the sentiment analysis result for each news
38
+ st.write("Original Text:", text)
39
+ st.write("Sentiment:", sentiment_results["label"])
40
+ st.write("Sentiment Score:", sentiment_results["score"])
41
+ st.write("---")
42
  else:
43
+ st.write("No news relevant to Energy | Oil.")
44
 
45
  def main():
46
  analyze_financial_news()