Kwasiasomani commited on
Commit
f980dca
1 Parent(s): 88b6c8c

Upload 4 files

Browse files
Files changed (4) hide show
  1. Eval_subset.csv +0 -0
  2. Streamlit_app.py +96 -0
  3. image1.jpg +0 -0
  4. image2.png +0 -0
Eval_subset.csv ADDED
The diff for this file is too large to render. See raw diff
 
Streamlit_app.py ADDED
@@ -0,0 +1,96 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import transformers
4
+ import torch
5
+ import pandas as pd
6
+ import plotly.express as px
7
+ import matplotlib.pyplot as plt
8
+ import select
9
+ from PIL import Image
10
+
11
+
12
+
13
+ # Load the dataset
14
+ df = pd.read_csv('Eval_subset.csv')
15
+ st.set_page_config(
16
+ page_title="Twitter Sentiment Analyzer", page_icon="📊", layout="wide"
17
+ )
18
+
19
+ #Image Description
20
+ image = Image.open('image1.jpg')
21
+ image_y = Image.open('image2.png')
22
+ st.image([image,image_y])
23
+
24
+
25
+ @st.cache_resource
26
+ def get_model():
27
+ model = transformers.AutoModelForSequenceClassification.from_pretrained("Kwasiasomani/Finetuned-Distilbert-base-model")
28
+ tokenizer = transformers.AutoTokenizer.from_pretrained("Kwasiasomani/Finetuned-Distilbert-base-model")
29
+ return tokenizer,model
30
+
31
+ tokenizer, model = get_model()
32
+
33
+ st.header("Covid19 Twitter Sentimental Analysis")
34
+ st.text("This app uses Distilbert-base-uncased for the analysis.")
35
+ add_text_sidebar = st.sidebar.title("Menu")
36
+ with st.sidebar:
37
+ st.title("Twitter Sentiment Analyzer")
38
+
39
+ st.markdown(
40
+ """
41
+ <div style="text-align: justify;">
42
+ This app performs sentiment analysis on the latest tweets based on
43
+ the entered search term. Since the app can only predict positive or
44
+ negative, and neutral sentiment, it is more suitable towards analyzing the
45
+ sentiment of brand, product, service, company, or person.
46
+ Only English tweets are supported.
47
+ </div>
48
+ """,
49
+ unsafe_allow_html=True,
50
+ )
51
+
52
+ #Graphical representation
53
+ st.sidebar.markdown("### Number of tweets by sentiment")
54
+ sentiment_count = df['safe_text'].value_counts()
55
+ sentiment_count = pd.DataFrame({'Sentiment':sentiment_count.index, 'Tweets':sentiment_count.values})
56
+ if not st.sidebar.checkbox("Hide", True):
57
+ st.markdown("### Number of tweets by sentiment")
58
+ if select == 'Bar plot':
59
+ fig = px.bar(sentiment_count, x='Sentiment', y='Tweets', color='Tweets', height=50)
60
+ st.plotly_chart(fig)
61
+ else:
62
+ fig = px.pie(sentiment_count, values='Tweets', names='Sentiment')
63
+ st.plotly_chart(fig)
64
+
65
+
66
+
67
+
68
+
69
+ # Side view description
70
+ st.sidebar.subheader("Show random tweet")
71
+ random_tweet = st.sidebar.radio('Sentiment', ('positive', 'neutral', 'negative'))
72
+ st.sidebar.markdown(df['safe_text'])
73
+
74
+
75
+ st.markdown("[Github link](https://github.com/kwasiasomani)")
76
+ st.markdown("[Medium link](https://medium.com/@kwasiasomani85)")
77
+ st.markdown('Created by Foster,Kwasi,Linda,Stella,Joshua and Bright')
78
+ user_input = st.text_area('Enter text to predict')
79
+ button = st.button('predict')
80
+
81
+
82
+ # Define Helper Function
83
+ label = {0: 'Negative', 1:'Neutral', 2:'Positive'}
84
+
85
+
86
+
87
+ # Prediction
88
+ if user_input and button:
89
+ test_input = tokenizer([user_input],return_tensors='pt')
90
+ st.slider("Number of tweets", min_value=100, max_value=2000, key="user_input")
91
+
92
+ # Test output
93
+ output = model(**test_input)
94
+ st.write('Logits:',output.logits)
95
+ predicted_class = np.argmax(output.logits.detach().numpy())
96
+ st.write('prediction:',label[predicted_class])
image1.jpg ADDED
image2.png ADDED