bright1's picture
Added app files
c9afa60
raw
history blame
3.49 kB
import streamlit as st
import pandas as pd
import numpy as np
# from scipy.special import softmax
# import os
from utils import run_sentiment_analysis, preprocess
from transformers import AutoTokenizer, AutoConfig,AutoModelForSequenceClassification
import os
import time
# Requirements
model_path = "bright1/fine-tuned-distilbert-base-uncased"
tokenizer = AutoTokenizer.from_pretrained(model_path)
config = AutoConfig.from_pretrained(model_path)
model = AutoModelForSequenceClassification.from_pretrained(model_path)
# dark_theme = set_theme()
st.set_page_config(
page_title="Tweet Analyzer",
page_icon="πŸ€–",
initial_sidebar_state="expanded",
menu_items={
'About': "# This is a header. This is an *extremely* cool app!"
}
)
my_expander = st.container()
# st.sidebar.selectbox('Menu', ['About', 'Model'])
with my_expander:
st.markdown("""
<style>
h1 {
text-align: center;
}
</style>
""", unsafe_allow_html=True)
st.title(':green[Covid-19 Vaccines Tweets Analyzer]')
st.sidebar.markdown("""
## Demo App
This app analyzes your tweets on covid vaccines and classifies them us Neutral, Negative or Positive
""")
# my_expander.write('Container')
# create a three column layout
col1, col2, col3 = st.columns((1.6, 1,0.3))
# col2.markdown("""
# <p style= font-color:red>
# Results from Analyzer
# </p>
# """,unsafe_allow_html=True)
st.markdown("""
<style>
p {
font-color: blue;
}
</style>
""", unsafe_allow_html=True)
tweet = col1.text_area('Tweets to analyze',height=200, max_chars=520, placeholder='Write your Tweets here')
colA, colb, colc, cold = st.columns(4)
clear_button = colA.button(label='Clear', type='secondary', use_container_width=True)
submit_button = colb.button(label='Submit', type='primary', use_container_width=True)
empty_container = col2.container()
empty_container.text("Results from Analyzer")
empty_container2 = col3.container()
empty_container2.text('Scores')
text = preprocess(tweet)
results = run_sentiment_analysis(text=text, model=model, tokenizer=tokenizer)
if submit_button:
success_message = st.success('Success', icon="βœ…")
with empty_container:
neutral = st.progress(value=results['Neutral'], text='Neutral',)
negative = st.progress(value=results['Negative'], text='Negative')
positive = st.progress(value=results['Positive'], text='Positive')
with empty_container2:
st.markdown(
"""
<style>
[data-testid="stMetricValue"] {
font-size: 20px;
}
</style>
""",
unsafe_allow_html=True,
)
neutral_score = st.metric(label='Score', value=round(results['Neutral'], 4), label_visibility='collapsed')
negative_score = st.metric(label='Score', value=round(results['Negative'], 4), label_visibility='collapsed')
positive_score = st.metric(label='Score', value=round(results['Positive'], 4), label_visibility='collapsed')
time.sleep(5)
success_message.empty()
interpret_button = col2.button(label='Interpret',type='secondary', use_container_width=True)
# st.help()
# create a date input to receive date