File size: 1,229 Bytes
35f56ba
7749ef6
47ef74f
cfa2b70
d71bb22
47ef74f
e43f53b
47ef74f
 
cfa2b70
c704d04
 
47ef74f
 
 
 
cfa2b70
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import tensorflow as tf
from transformers import pipeline
from textblob import TextBlob

classifier = pipeline(task="sentiment-analysis")

textIn = st.text_input("Input Text Here:", "I really like the color of your car!")

option = st.selectbox('Which pre-trained model would you like for your sentiment analysis?',('Pipeline', 'textblob', ''))

st.write('You selected:', option)

# pipeline
preds = classifier(textIn)
preds = [{"score": round(pred["score"], 4), "label": pred["label"]} for pred in preds]
st.write('According to Pipeline, input text is ', preds[0]['label'], ' with a confidence of ', preds[0]['score'])

# textblob
polarity = TextBlob(textIn).sentiment.polarity
sentiment = ''
if score < 0:
    sentiment = 'Negative'
elif score == 0:
    sentiment = 'Neutral'
else:
    sentiment = 'Positive'
st.write('According to textblob, input text is ', sentiment, ' with a polarity (subjectivity score) of ', polarity)


# def getAnalysis(score):
#     if score < 0:
#         return 'Negative'
#     elif score == 0:
#         return 'Neutral'
#     else:
#         return 'Positive'
# df['polarity'] = df[text].apply(textblob_polarity)
# df['classification'] = df['polarity'].apply(getAnalysis)