Kwasiasomani commited on
Commit
f0eaa2c
β€’
1 Parent(s): 0920dec

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -3
app.py CHANGED
@@ -2,6 +2,14 @@ import streamlit as st
2
  import numpy as np
3
  import transformers
4
  import torch
 
 
 
 
 
 
 
 
5
 
6
 
7
  @st.cache_resource
@@ -12,18 +20,61 @@ def get_model():
12
 
13
  tokenizer, model = get_model()
14
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
 
 
16
  user_input = st.text_area('Enter text to predict')
17
  button = st.button('predict')
18
 
19
 
20
-
21
- # Define the Helper function
22
  label = {0: 'Negative', 1:'Neutral', 2:'Positive'}
23
 
 
 
 
24
  if user_input and button:
25
  test_input = tokenizer([user_input],return_tensors='pt')
26
-
 
27
  # Test output
28
  output = model(**test_input)
29
  st.write('Logits:',output.logits)
 
2
  import numpy as np
3
  import transformers
4
  import torch
5
+ import pandas as pd
6
+ import plotly.express as px
7
+
8
+
9
+ df = pd.read_csv('Eval_subset.csv')
10
+ st.set_page_config(
11
+ page_title="Twitter Sentiment Analyzer", page_icon="πŸ“Š", layout="wide"
12
+ )
13
 
14
 
15
  @st.cache_resource
 
20
 
21
  tokenizer, model = get_model()
22
 
23
+ st.header("Covid19 Twitter Sentimental Analysis")
24
+ st.text("This app uses Distilbert-base-uncased for the analysis.")
25
+ add_text_sidebar = st.sidebar.title("Menu")
26
+ #add_text_sidebar = st.sidebar.text("Just some random text.")
27
+ with st.sidebar:
28
+ st.title("Twitter Sentiment Analyzer")
29
+
30
+ st.markdown(
31
+ """
32
+ <div style="text-align: justify;">
33
+ This app performs sentiment analysis on the latest tweets based on
34
+ the entered search term. Since the app can only predict positive or
35
+ negative, and neutral sentiment, it is more suitable towards analyzing the
36
+ sentiment of brand, product, service, company, or person.
37
+ Only English tweets are supported.
38
+ </div>
39
+ """,
40
+ unsafe_allow_html=True,
41
+ )
42
+
43
+ st.sidebar.markdown("### Number of tweets by sentiment")
44
+ select = st.sidebar.selectbox('Visualization type', ['Bar plot', 'Pie chart'], key='1')
45
+ sentiment_count = df['safe_text'].value_counts()
46
+ sentiment_count = pd.DataFrame({'Sentiment':sentiment_count.index, 'Tweets':sentiment_count.values})
47
+ if not st.sidebar.checkbox("Hide", True):
48
+ st.markdown("### Number of tweets by sentiment")
49
+ if select == 'Bar plot':
50
+ fig = px.bar(sentiment_count, x='Sentiment', y='Tweets', color='Tweets', height=500)
51
+ st.plotly_chart(fig)
52
+ else:
53
+ fig = px.pie(sentiment_count, values='Tweets', names='Sentiment')
54
+ st.plotly_chart(fig)
55
+
56
+
57
+ st.sidebar.subheader("Show random tweet")
58
+ random_tweet = st.sidebar.radio('Sentiment', ('positive', 'neutral', 'negative'))
59
+ st.sidebar.markdown(df['safe_text'])
60
+
61
 
62
+ st.markdown("[Github link](https://github.com/tmtsmrsl/TwitterSentimentAnalyzer)")
63
+ st.markdown('Created by Foster,Kwasi,Linda,Stella,Joshua,Bright')
64
  user_input = st.text_area('Enter text to predict')
65
  button = st.button('predict')
66
 
67
 
68
+ # Define Helper Function
 
69
  label = {0: 'Negative', 1:'Neutral', 2:'Positive'}
70
 
71
+
72
+
73
+
74
  if user_input and button:
75
  test_input = tokenizer([user_input],return_tensors='pt')
76
+ st.slider("Number of tweets", min_value=100, max_value=2000, key="user_input")
77
+
78
  # Test output
79
  output = model(**test_input)
80
  st.write('Logits:',output.logits)