File size: 3,494 Bytes
c9afa60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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