nickmuchi commited on
Commit
37e8b9d
β€’
1 Parent(s): 9c14ab9

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