simon-kurbiel commited on
Commit
9f33a31
1 Parent(s): aceb17b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+ import streamlit as st
3
+ from transformers import pipeline
4
+
5
+ import torch
6
+
7
+ def bertweet(data):
8
+ specific_model = pipeline(model="finiteautomata/bertweet-base-sentiment-analysis")
9
+ result = specific_model(data)
10
+ label = result[0]['label']
11
+ score = result[0]['score']
12
+
13
+ return label, score
14
+
15
+ def roberta(data):
16
+ specific_model = pipeline(model="cardiffnlp/twitter-roberta-base-sentiment")
17
+ result = specific_model(data)
18
+ label = result[0]['label']
19
+ score = result[0]['score']
20
+
21
+ if(label == 'LABEL_0'):
22
+ label = 'Negative'
23
+ elif(label == 'LABEL_1'):
24
+ label = 'Neutral'
25
+ else:
26
+ label = 'Positive'
27
+
28
+ return label, score
29
+
30
+ def getSent(data, model):
31
+ if(model == 'Bertweet'):
32
+ label,score = bertweet(data)
33
+ col1, col2 = st.columns(2)
34
+ col1.metric("Feeling",label,None)
35
+ col2.metric("Score",score,None)
36
+ elif(model == 'Roberta'):
37
+ label,score = roberta(data)
38
+ col1, col2 = st.columns(2)
39
+ col1.metric("Feeling",label,None)
40
+ col2.metric("Score",score,None)
41
+
42
+ def rendPage():
43
+ st.title("Sentiment Analysis")
44
+ userText = st.text_input('User Input', "Hope you are having a great day!")
45
+ st.text("")
46
+ type = st.selectbox(
47
+ 'Choose your model',
48
+ ('Bertweet','Roberta',))
49
+ st.text("")
50
+
51
+ if st.button('Calculate'):
52
+ if(userText!="" and type != None):
53
+ st.text("")
54
+ getSent(userText,type)
55
+
56
+ rendPage()