simon-kurbiel commited on
Commit
377bc30
1 Parent(s): c8f1af2

added app.py

Browse files
Files changed (3) hide show
  1. README.md +12 -2
  2. app.py +56 -0
  3. requirements.txt +5 -0
README.md CHANGED
@@ -1,2 +1,12 @@
1
- # sentiment-analysis
2
- sentiment analysis app using streamlit
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Sen Analysis
3
+ emoji: 🏃
4
+ colorFrom: blue
5
+ colorTo: red
6
+ sdk: streamlit
7
+ sdk_version: 1.17.0
8
+ app_file: app.py
9
+ pinned: false
10
+ ---
11
+
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
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()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ numpy
2
+ streamlit
3
+ transformers
4
+ tensorflow
5
+ torch