Update pages/1_Earnings_Sentiment_Analysis_π_.py
Browse files
pages/1_Earnings_Sentiment_Analysis_π_.py
CHANGED
@@ -1,4 +1,7 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
2 |
|
3 |
st.set_page_config(page_title="Earnings Sentiment Analysis", page_icon="π")
|
4 |
st.sidebar.header("Sentiment Analysis")
|
@@ -11,6 +14,89 @@ st.subheader(title)
|
|
11 |
|
12 |
earnings_passages = results['text']
|
13 |
|
|
|
|
|
|
|
14 |
with open('earnings.txt','w') as f:
|
15 |
f.write(earnings_passages)
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
import plotly_express as px
|
4 |
+
import plotly.graph_objects as go
|
5 |
|
6 |
st.set_page_config(page_title="Earnings Sentiment Analysis", page_icon="π")
|
7 |
st.sidebar.header("Sentiment Analysis")
|
|
|
14 |
|
15 |
earnings_passages = results['text']
|
16 |
|
17 |
+
with st.expander("See Transcribed Earnings Text"):
|
18 |
+
st.write(earnings_passages)
|
19 |
+
|
20 |
with open('earnings.txt','w') as f:
|
21 |
f.write(earnings_passages)
|
22 |
|
23 |
+
with open('earnings.txt','r') as f:
|
24 |
+
earnings_passages = f.read()
|
25 |
+
|
26 |
+
earnings_sentiment, earnings_sentences = sent_pipe(earnings_passages)
|
27 |
+
|
28 |
+
## Save to a dataframe for ease of visualization
|
29 |
+
sen_df = pd.DataFrame(earnings_sentiment)
|
30 |
+
sen_df['text'] = earnings_sentences
|
31 |
+
grouped = pd.DataFrame(sen_df['label'].value_counts()).reset_index()
|
32 |
+
grouped.columns = ['sentiment','count']
|
33 |
+
|
34 |
+
# Display number of positive, negative and neutral sentiments
|
35 |
+
fig = px.bar(grouped, x='sentiment', y='count', color='sentiment', color_discrete_map={"Negative":"firebrick","Neutral":\
|
36 |
+
"navajowhite","Positive":"darkgreen"},\
|
37 |
+
title='Earnings Sentiment')
|
38 |
+
|
39 |
+
fig.update_layout(
|
40 |
+
showlegend=False,
|
41 |
+
autosize=True,
|
42 |
+
margin=dict(
|
43 |
+
l=50,
|
44 |
+
r=50,
|
45 |
+
b=50,
|
46 |
+
t=50,
|
47 |
+
pad=4
|
48 |
+
)
|
49 |
+
)
|
50 |
+
|
51 |
+
st.plotly_chart(fig)
|
52 |
+
|
53 |
+
## Display sentiment score
|
54 |
+
pos_perc = grouped[grouped['sentiment']=='Positive']['count'].iloc[0]*100/sen_df.shape[0]
|
55 |
+
neg_perc = grouped[grouped['sentiment']=='Negative']['count'].iloc[0]*100/sen_df.shape[0]
|
56 |
+
neu_perc = grouped[grouped['sentiment']=='Neutral']['count'].iloc[0]*100/sen_df.shape[0]
|
57 |
+
|
58 |
+
sentiment_score = neu_perc+pos_perc-neg_perc
|
59 |
+
|
60 |
+
fig = go.Figure()
|
61 |
+
|
62 |
+
fig.add_trace(go.Indicator(
|
63 |
+
mode = "delta",
|
64 |
+
value = sentiment_score,
|
65 |
+
domain = {'row': 1, 'column': 1}))
|
66 |
+
|
67 |
+
fig.update_layout(
|
68 |
+
template = {'data' : {'indicator': [{
|
69 |
+
'title': {'text': "Sentiment score"},
|
70 |
+
'mode' : "number+delta+gauge",
|
71 |
+
'delta' : {'reference': 50}}]
|
72 |
+
}},
|
73 |
+
autosize=False,
|
74 |
+
width=400,
|
75 |
+
height=500,
|
76 |
+
margin=dict(
|
77 |
+
l=20,
|
78 |
+
r=50,
|
79 |
+
b=50,
|
80 |
+
pad=4
|
81 |
+
)
|
82 |
+
)
|
83 |
+
|
84 |
+
## Display negative sentence locations
|
85 |
+
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')
|
86 |
+
|
87 |
+
|
88 |
+
fig.update_layout(
|
89 |
+
showlegend=False,
|
90 |
+
autosize=False,
|
91 |
+
width=1000,
|
92 |
+
height=500,
|
93 |
+
margin=dict(
|
94 |
+
l=50,
|
95 |
+
r=50,
|
96 |
+
b=50,
|
97 |
+
t=50,
|
98 |
+
pad=4
|
99 |
+
)
|
100 |
+
)
|
101 |
+
|
102 |
+
st.plotly_chart(fig)
|