File size: 3,529 Bytes
caf57e7 086edea 610814b ac896ff caf57e7 40f7988 0a4ef0e 5a1ffea ab20b35 0a4ef0e 5a1ffea 0a4ef0e 5a1ffea 086edea 5a1ffea 0f2bd46 5a1ffea 086edea 5a1ffea 086edea 5a1ffea 086edea 5a1ffea |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 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 |
import streamlit as st
import pandas as pd
import plotly_express as px
import plotly.graph_objects as go
from functions import *
import validators
st.set_page_config(page_title="Earnings Sentiment Analysis", page_icon="π")
st.sidebar.header("Sentiment Analysis")
st.markdown("## Earnings Sentiment Analysis with FinBert-Tone")
if st.session_state.url or st.session_state.upload:
results, title = inference(st.session_state.url,st.session_state.upload)
st.subheader(title)
earnings_passages = results['text']
with open('earnings.txt','w') as f:
f.write(earnings_passages)
with open('earnings.txt','r') as f:
earnings_passages = f.read()
earnings_sentiment, earnings_sentences = sent_pipe(earnings_passages)
with st.expander("See Transcribed Earnings Text"):
st.write(f"Number of Sentences: {len(earnings_ssentences)}")
st.write(earnings_passages)
## Save to a dataframe for ease of visualization
sen_df = pd.DataFrame(earnings_sentiment)
sen_df['text'] = earnings_sentences
grouped = pd.DataFrame(sen_df['label'].value_counts()).reset_index()
grouped.columns = ['sentiment','count']
# Display number of positive, negative and neutral sentiments
fig = px.bar(grouped, x='sentiment', y='count', color='sentiment', color_discrete_map={"Negative":"firebrick","Neutral":\
"navajowhite","Positive":"darkgreen"},\
title='Earnings Sentiment')
fig.update_layout(
showlegend=False,
autosize=True,
margin=dict(
l=50,
r=50,
b=50,
t=50,
pad=4
)
)
col1, col2 = st.columns(2)
col1.plotly_chart(fig)
## Display sentiment score
pos_perc = grouped[grouped['sentiment']=='Positive']['count'].iloc[0]*100/sen_df.shape[0]
neg_perc = grouped[grouped['sentiment']=='Negative']['count'].iloc[0]*100/sen_df.shape[0]
neu_perc = grouped[grouped['sentiment']=='Neutral']['count'].iloc[0]*100/sen_df.shape[0]
sentiment_score = neu_perc+pos_perc-neg_perc
fig = go.Figure()
fig.add_trace(go.Indicator(
mode = "delta",
value = sentiment_score,
domain = {'row': 1, 'column': 1}))
fig.update_layout(
template = {'data' : {'indicator': [{
'title': {'text': "Sentiment score"},
'mode' : "number+delta+gauge",
'delta' : {'reference': 50}}]
}},
autosize=False,
width=400,
height=500,
margin=dict(
l=20,
r=50,
b=50,
pad=4
)
)
col2.plotly_chart(fig)
## Display negative sentence locations
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')
fig.update_layout(
showlegend=False,
autosize=False,
width=1000,
height=500,
margin=dict(
l=50,
r=50,
b=50,
t=50,
pad=4
)
)
st.plotly_chart(fig)
else:
st.write("No YouTube URL or file upload detected") |