Update pages/1_Earnings_Sentiment_Analysis_π_.py
Browse files
pages/1_Earnings_Sentiment_Analysis_π_.py
CHANGED
@@ -12,104 +12,111 @@ st.markdown("## Earnings Sentiment Analysis with FinBert-Tone")
|
|
12 |
if "url" not in st.session_state:
|
13 |
st.session_state.url = ''
|
14 |
|
15 |
-
|
16 |
-
|
17 |
-
results, title = inference(st.session_state.url,st.session_state.upload)
|
18 |
|
19 |
-
st.
|
20 |
-
|
21 |
-
earnings_passages = results['text']
|
22 |
-
|
23 |
-
st.session_state['earnings_passages'] = earnings_passages
|
24 |
|
25 |
-
|
26 |
|
27 |
-
|
28 |
-
st.write(f"Number of Sentences: {len(earnings_sentences)}")
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
)
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
)
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
)
|
110 |
-
|
111 |
-
|
112 |
-
|
|
|
113 |
|
114 |
-
|
|
|
|
|
|
|
115 |
st.write("No YouTube URL or file upload detected")
|
|
|
12 |
if "url" not in st.session_state:
|
13 |
st.session_state.url = ''
|
14 |
|
15 |
+
try:
|
|
|
|
|
16 |
|
17 |
+
if st.session_state['url'] is not None or st.session_state['upload'] is not None:
|
|
|
|
|
|
|
|
|
18 |
|
19 |
+
results, title = inference(st.session_state.url,st.session_state.upload)
|
20 |
|
21 |
+
st.subheader(title)
|
|
|
22 |
|
23 |
+
earnings_passages = results['text']
|
24 |
+
|
25 |
+
st.session_state['earnings_passages'] = earnings_passages
|
26 |
+
|
27 |
+
earnings_sentiment, earnings_sentences = sentiment_pipe(earnings_passages)
|
28 |
+
|
29 |
+
with st.expander("See Transcribed Earnings Text"):
|
30 |
+
st.write(f"Number of Sentences: {len(earnings_sentences)}")
|
31 |
+
|
32 |
+
st.write(earnings_passages)
|
33 |
+
|
34 |
+
|
35 |
+
## Save to a dataframe for ease of visualization
|
36 |
+
sen_df = pd.DataFrame(earnings_sentiment)
|
37 |
+
sen_df['text'] = earnings_sentences
|
38 |
+
grouped = pd.DataFrame(sen_df['label'].value_counts()).reset_index()
|
39 |
+
grouped.columns = ['sentiment','count']
|
40 |
+
|
41 |
+
st.session_state['sen_df'] = sen_df
|
42 |
+
|
43 |
+
# Display number of positive, negative and neutral sentiments
|
44 |
+
fig = px.bar(grouped, x='sentiment', y='count', color='sentiment', color_discrete_map={"Negative":"firebrick","Neutral":\
|
45 |
+
"navajowhite","Positive":"darkgreen"},\
|
46 |
+
title='Earnings Sentiment')
|
47 |
+
|
48 |
+
fig.update_layout(
|
49 |
+
showlegend=False,
|
50 |
+
autosize=True,
|
51 |
+
margin=dict(
|
52 |
+
l=25,
|
53 |
+
r=25,
|
54 |
+
b=25,
|
55 |
+
t=50,
|
56 |
+
pad=2
|
57 |
+
)
|
58 |
)
|
59 |
+
|
60 |
+
|
61 |
+
st.plotly_chart(fig)
|
62 |
+
|
63 |
+
## Display sentiment score
|
64 |
+
pos_perc = grouped[grouped['sentiment']=='Positive']['count'].iloc[0]*100/sen_df.shape[0]
|
65 |
+
neg_perc = grouped[grouped['sentiment']=='Negative']['count'].iloc[0]*100/sen_df.shape[0]
|
66 |
+
neu_perc = grouped[grouped['sentiment']=='Neutral']['count'].iloc[0]*100/sen_df.shape[0]
|
67 |
+
|
68 |
+
sentiment_score = neu_perc+pos_perc-neg_perc
|
69 |
+
|
70 |
+
fig_1 = go.Figure()
|
71 |
+
|
72 |
+
fig_1.add_trace(go.Indicator(
|
73 |
+
mode = "delta",
|
74 |
+
value = sentiment_score,
|
75 |
+
domain = {'row': 1, 'column': 1}))
|
76 |
+
|
77 |
+
fig_1.update_layout(
|
78 |
+
template = {'data' : {'indicator': [{
|
79 |
+
'title': {'text': "Sentiment Score"},
|
80 |
+
'mode' : "number+delta+gauge",
|
81 |
+
'delta' : {'reference': 50}}]
|
82 |
+
}},
|
83 |
+
autosize=False,
|
84 |
+
width=250,
|
85 |
+
height=250,
|
86 |
+
margin=dict(
|
87 |
+
l=5,
|
88 |
+
r=5,
|
89 |
+
b=5,
|
90 |
+
pad=2
|
91 |
+
)
|
92 |
)
|
93 |
+
|
94 |
+
with st.sidebar:
|
95 |
+
|
96 |
+
st.plotly_chart(fig_1)
|
97 |
+
|
98 |
+
## Display negative sentence locations
|
99 |
+
fig = px.scatter(sen_df, y='label', color='label', size='score', hover_data=['text'], color_discrete_map={"Negative":"firebrick","Neutral":"navajowhite","Positive":"darkgreen"}, title='Sentiment Score Distribution')
|
100 |
+
|
101 |
+
|
102 |
+
fig.update_layout(
|
103 |
+
showlegend=False,
|
104 |
+
autosize=True,
|
105 |
+
width=1000,
|
106 |
+
height=500,
|
107 |
+
margin=dict(
|
108 |
+
b=5,
|
109 |
+
t=50,
|
110 |
+
pad=4
|
111 |
+
)
|
112 |
)
|
113 |
+
|
114 |
+
st.plotly_chart(fig)
|
115 |
+
|
116 |
+
else:
|
117 |
|
118 |
+
st.write("No YouTube URL or file upload detected")
|
119 |
+
|
120 |
+
except AttributeError:
|
121 |
+
|
122 |
st.write("No YouTube URL or file upload detected")
|