Jeffrey Rathgeber Jr
testblob tester up
0a5c8ee unverified
raw
history blame
1.12 kB
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
def textblob_polarity(text):
return TextBlob(text).sentiment.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)
st.write('According to textblob, input text is ', df['classification'], ' with a polarity (subjectivity score) of ', df['polarity'])