nickmuchi commited on
Commit
5a1ffea
β€’
1 Parent(s): ab20b35

Update pages/1_Earnings_Sentiment_Analysis_πŸ“ˆ_.py

Browse files
pages/1_Earnings_Sentiment_Analysis_πŸ“ˆ_.py CHANGED
@@ -9,104 +9,107 @@ st.set_page_config(page_title="Earnings Sentiment Analysis", page_icon="πŸ“ˆ")
9
  st.sidebar.header("Sentiment Analysis")
10
  st.markdown("## Earnings Sentiment Analysis with FinBert-Tone")
11
 
12
- if st.session_state.url.on_change or st.session_state.upload.on_change:
13
 
14
  results, title = inference(st.session_state.url,st.session_state.upload)
15
 
16
- st.subheader(title)
17
-
18
- earnings_passages = results['text']
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
- with st.expander("See Transcribed Earnings Text"):
29
- st.write(f"Number of Sentences: {len(earnings_ssentences)}")
 
 
 
30
 
31
- st.write(earnings_passages)
32
-
33
-
34
- ## Save to a dataframe for ease of visualization
35
- sen_df = pd.DataFrame(earnings_sentiment)
36
- sen_df['text'] = earnings_sentences
37
- grouped = pd.DataFrame(sen_df['label'].value_counts()).reset_index()
38
- grouped.columns = ['sentiment','count']
39
-
40
- # Display number of positive, negative and neutral sentiments
41
- fig = px.bar(grouped, x='sentiment', y='count', color='sentiment', color_discrete_map={"Negative":"firebrick","Neutral":\
42
- "navajowhite","Positive":"darkgreen"},\
43
- title='Earnings Sentiment')
44
-
45
- fig.update_layout(
46
- showlegend=False,
47
- autosize=True,
48
- margin=dict(
49
- l=50,
50
- r=50,
51
- b=50,
52
- t=50,
53
- pad=4
 
 
 
 
54
  )
55
- )
56
-
57
- col1, col2 = st.columns(2)
58
-
59
- col1.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 = go.Figure()
69
-
70
- fig.add_trace(go.Indicator(
71
- mode = "delta",
72
- value = sentiment_score,
73
- domain = {'row': 1, 'column': 1}))
74
-
75
- fig.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=400,
83
- height=500,
84
- margin=dict(
85
- l=20,
86
- r=50,
87
- b=50,
88
- pad=4
89
  )
90
- )
91
-
92
- col2.plotly_chart(fig)
93
-
94
- ## Display negative sentence locations
95
- 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')
96
-
97
-
98
- fig.update_layout(
99
- showlegend=False,
100
- autosize=False,
101
- width=1000,
102
- height=500,
103
- margin=dict(
104
- l=50,
105
- r=50,
106
- b=50,
107
- t=50,
108
- pad=4
109
  )
110
- )
111
-
112
- st.plotly_chart(fig)
 
 
 
9
  st.sidebar.header("Sentiment Analysis")
10
  st.markdown("## Earnings Sentiment Analysis with FinBert-Tone")
11
 
12
+ if st.session_state.url or st.session_state.upload:
13
 
14
  results, title = inference(st.session_state.url,st.session_state.upload)
15
 
16
+ st.subheader(title)
 
 
 
 
 
17
 
18
+ earnings_passages = results['text']
 
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
+ with st.expander("See Transcribed Earnings Text"):
29
+ st.write(f"Number of Sentences: {len(earnings_ssentences)}")
30
+
31
+ st.write(earnings_passages)
32
+
33
+
34
+ ## Save to a dataframe for ease of visualization
35
+ sen_df = pd.DataFrame(earnings_sentiment)
36
+ sen_df['text'] = earnings_sentences
37
+ grouped = pd.DataFrame(sen_df['label'].value_counts()).reset_index()
38
+ grouped.columns = ['sentiment','count']
39
+
40
+ # Display number of positive, negative and neutral sentiments
41
+ fig = px.bar(grouped, x='sentiment', y='count', color='sentiment', color_discrete_map={"Negative":"firebrick","Neutral":\
42
+ "navajowhite","Positive":"darkgreen"},\
43
+ title='Earnings Sentiment')
44
+
45
+ fig.update_layout(
46
+ showlegend=False,
47
+ autosize=True,
48
+ margin=dict(
49
+ l=50,
50
+ r=50,
51
+ b=50,
52
+ t=50,
53
+ pad=4
54
+ )
55
  )
56
+
57
+ col1, col2 = st.columns(2)
58
+
59
+ col1.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 = go.Figure()
69
+
70
+ fig.add_trace(go.Indicator(
71
+ mode = "delta",
72
+ value = sentiment_score,
73
+ domain = {'row': 1, 'column': 1}))
74
+
75
+ fig.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=400,
83
+ height=500,
84
+ margin=dict(
85
+ l=20,
86
+ r=50,
87
+ b=50,
88
+ pad=4
89
+ )
90
  )
91
+
92
+ col2.plotly_chart(fig)
93
+
94
+ ## Display negative sentence locations
95
+ 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')
96
+
97
+
98
+ fig.update_layout(
99
+ showlegend=False,
100
+ autosize=False,
101
+ width=1000,
102
+ height=500,
103
+ margin=dict(
104
+ l=50,
105
+ r=50,
106
+ b=50,
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")