File size: 4,052 Bytes
caf57e7 086edea 610814b ac896ff caf57e7 40f7988 0a4ef0e ed945e3 37e8b9d 0a4ef0e 37e8b9d 0af20e7 37e8b9d 0f2bd46 37e8b9d 5a1ffea 37e8b9d 5a1ffea 37e8b9d 5a1ffea 37e8b9d 5a1ffea 37e8b9d 5a1ffea 37e8b9d 7004c0a 37e8b9d 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 116 117 118 119 120 121 122 |
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 "url" not in st.session_state:
st.session_state.url = ''
try:
if st.session_state['url'] is not None or st.session_state['upload'] is not None:
results, title = inference(st.session_state.url,st.session_state.upload)
st.subheader(title)
earnings_passages = results['text']
st.session_state['earnings_passages'] = earnings_passages
earnings_sentiment, earnings_sentences = sentiment_pipe(earnings_passages)
with st.expander("See Transcribed Earnings Text"):
st.write(f"Number of Sentences: {len(earnings_sentences)}")
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']
st.session_state['sen_df'] = sen_df
# 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=25,
r=25,
b=25,
t=50,
pad=2
)
)
st.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_1 = go.Figure()
fig_1.add_trace(go.Indicator(
mode = "delta",
value = sentiment_score,
domain = {'row': 1, 'column': 1}))
fig_1.update_layout(
template = {'data' : {'indicator': [{
'title': {'text': "Sentiment Score"},
'mode' : "number+delta+gauge",
'delta' : {'reference': 50}}]
}},
autosize=False,
width=250,
height=250,
margin=dict(
l=5,
r=5,
b=5,
pad=2
)
)
with st.sidebar:
st.plotly_chart(fig_1)
## 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=True,
width=1000,
height=500,
margin=dict(
b=5,
t=50,
pad=4
)
)
st.plotly_chart(fig)
else:
st.write("No YouTube URL or file upload detected")
except (AttributeError, TypeError):
st.write("No YouTube URL or file upload detected") |