import streamlit as st import pandas as pd import plotly_express as px import plotly.graph_objects as go from functions import * st.set_page_config(page_title="Earnings Sentiment Analysis", page_icon="📈") st.sidebar.header("Sentiment Analysis") st.markdown("## Earnings Sentiment Analysis with FinBert-Tone") results, title = inference(url_input,upload_wav) 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)