TanishqO0F commited on
Commit
b420fee
·
verified ·
1 Parent(s): fbe563e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -15
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.graph_objects as go
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 = go.Figure(data=[go.Bar(
68
- x=news_df['Time'],
69
- y=news_df['Sentiment_Score'],
70
- marker_color=news_df['Sentiment'].map({'positive': 'green', 'neutral': 'gray', 'negative': 'red'})
71
- )])
72
- sentiment_fig.update_layout(title='News Sentiment Over Time', xaxis_title='Time', yaxis_title='Sentiment Score')
 
 
 
73
 
74
  return news_df, sentiment_fig
75
 
76
  # Gradio interface
77
  with gr.Blocks() as demo:
78
- gr.Markdown("#News Sentiment Analysis")
79
-
80
- topic = gr.Textbox(label="Enter a headline")
81
-
82
- analyze_btn = gr.Button(value="Analyze")
 
 
 
83
 
84
- news_output = gr.DataFrame(label="News and Sentiment Analysis")
85
- sentiment_plot = gr.Plot(label="Sentiment Analysis")
 
 
 
 
 
 
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()