Spaces:
Runtime error
Runtime error
Jeffrey Rathgeber Jr
commited on
testblob tester
Browse files
app.py
CHANGED
|
@@ -1,17 +1,40 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
import tensorflow as tf
|
| 3 |
from transformers import pipeline
|
| 4 |
-
|
| 5 |
|
| 6 |
classifier = pipeline(task="sentiment-analysis")
|
| 7 |
|
| 8 |
textIn = st.text_input("Input Text Here:", "I really like the color of your car!")
|
| 9 |
|
| 10 |
-
option = st.selectbox('Which pre-trained model would you like for your sentiment analysis?',('
|
| 11 |
|
| 12 |
st.write('You selected:', option)
|
| 13 |
|
| 14 |
# pipeline
|
| 15 |
preds = classifier(textIn)
|
| 16 |
preds = [{"score": round(pred["score"], 4), "label": pred["label"]} for pred in preds]
|
| 17 |
-
st.write('
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import tensorflow as tf
|
| 3 |
from transformers import pipeline
|
| 4 |
+
from textblob import TextBlob
|
| 5 |
|
| 6 |
classifier = pipeline(task="sentiment-analysis")
|
| 7 |
|
| 8 |
textIn = st.text_input("Input Text Here:", "I really like the color of your car!")
|
| 9 |
|
| 10 |
+
option = st.selectbox('Which pre-trained model would you like for your sentiment analysis?',('Pipeline', 'textblob', ''))
|
| 11 |
|
| 12 |
st.write('You selected:', option)
|
| 13 |
|
| 14 |
# pipeline
|
| 15 |
preds = classifier(textIn)
|
| 16 |
preds = [{"score": round(pred["score"], 4), "label": pred["label"]} for pred in preds]
|
| 17 |
+
st.write('According to Pipeline, input text is ', preds[0]['label'], ' with a confidence of ', preds[0]['score'])
|
| 18 |
+
|
| 19 |
+
# textblob
|
| 20 |
+
polarity = TextBlob(textIn).sentiment.polarity
|
| 21 |
+
sentiment = ''
|
| 22 |
+
if score < 0:
|
| 23 |
+
sentiment = 'Negative'
|
| 24 |
+
elif score == 0:
|
| 25 |
+
sentiment = 'Neutral'
|
| 26 |
+
else:
|
| 27 |
+
sentiment = 'Positive'
|
| 28 |
+
st.write('According to textblob, input text is ', sentiment, ' with a polarity (subjectivity score) of ', polarity)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
# def getAnalysis(score):
|
| 32 |
+
# if score < 0:
|
| 33 |
+
# return 'Negative'
|
| 34 |
+
# elif score == 0:
|
| 35 |
+
# return 'Neutral'
|
| 36 |
+
# else:
|
| 37 |
+
# return 'Positive'
|
| 38 |
+
# df['polarity'] = df[text].apply(textblob_polarity)
|
| 39 |
+
# df['classification'] = df['polarity'].apply(getAnalysis)
|
| 40 |
+
|