Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ import requests
|
|
3 |
from bs4 import BeautifulSoup
|
4 |
import pandas as pd
|
5 |
from transformers import pipeline
|
6 |
-
import plotly.
|
7 |
from datetime import datetime, timedelta
|
8 |
|
9 |
# Sentiment Analysis Model
|
@@ -64,25 +64,37 @@ def news_and_analysis(query):
|
|
64 |
news_df['Sentiment'], news_df['Sentiment_Score'] = zip(*news_df['Title'].apply(analyze_sentiment))
|
65 |
|
66 |
# Create sentiment plot
|
67 |
-
sentiment_fig =
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
|
|
|
|
|
|
73 |
|
74 |
return news_df, sentiment_fig
|
75 |
|
76 |
# Gradio interface
|
77 |
with gr.Blocks() as demo:
|
78 |
-
gr.Markdown(
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
|
|
|
|
|
|
83 |
|
84 |
-
|
85 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
|
87 |
analyze_btn.click(
|
88 |
news_and_analysis,
|
@@ -91,4 +103,4 @@ with gr.Blocks() as demo:
|
|
91 |
)
|
92 |
|
93 |
if __name__ == "__main__":
|
94 |
-
demo.launch()
|
|
|
3 |
from bs4 import BeautifulSoup
|
4 |
import pandas as pd
|
5 |
from transformers import pipeline
|
6 |
+
import plotly.express as px
|
7 |
from datetime import datetime, timedelta
|
8 |
|
9 |
# Sentiment Analysis Model
|
|
|
64 |
news_df['Sentiment'], news_df['Sentiment_Score'] = zip(*news_df['Title'].apply(analyze_sentiment))
|
65 |
|
66 |
# Create sentiment plot
|
67 |
+
sentiment_fig = px.bar(
|
68 |
+
news_df,
|
69 |
+
x='Time',
|
70 |
+
y='Sentiment_Score',
|
71 |
+
color='Sentiment',
|
72 |
+
color_discrete_map={'positive': 'green', 'neutral': 'gray', 'negative': 'red'},
|
73 |
+
title='News Sentiment Over Time',
|
74 |
+
labels={'Time': 'Publication Time', 'Sentiment_Score': 'Sentiment Score'}
|
75 |
+
)
|
76 |
|
77 |
return news_df, sentiment_fig
|
78 |
|
79 |
# Gradio interface
|
80 |
with gr.Blocks() as demo:
|
81 |
+
gr.Markdown(
|
82 |
+
"""
|
83 |
+
# Financial News Sentiment Analysis
|
84 |
+
|
85 |
+
Analyze the sentiment of news articles related to financial topics or companies.
|
86 |
+
Enter a topic or company name to get started.
|
87 |
+
"""
|
88 |
+
)
|
89 |
|
90 |
+
with gr.Row():
|
91 |
+
with gr.Column():
|
92 |
+
topic = gr.Textbox(label="Enter a financial topic or company name", placeholder="e.g., Apple Inc.")
|
93 |
+
analyze_btn = gr.Button(value="Analyze")
|
94 |
+
|
95 |
+
with gr.Column():
|
96 |
+
news_output = gr.DataFrame(label="News and Sentiment Analysis")
|
97 |
+
sentiment_plot = gr.Plot(label="Sentiment Analysis")
|
98 |
|
99 |
analyze_btn.click(
|
100 |
news_and_analysis,
|
|
|
103 |
)
|
104 |
|
105 |
if __name__ == "__main__":
|
106 |
+
demo.launch()
|