Spaces:
No application file
No application file
Commit ·
d3db004
1
Parent(s): 2dc0000
Update app.py
Browse files
app.py
CHANGED
|
@@ -11,9 +11,9 @@ models = {
|
|
| 11 |
|
| 12 |
def textblob_sentiment(text):
|
| 13 |
polarity = TextBlob(text).sentiment.polarity
|
| 14 |
-
if polarity > 0:
|
| 15 |
return 'Positive'
|
| 16 |
-
elif polarity < 0:
|
| 17 |
return 'Negative'
|
| 18 |
else:
|
| 19 |
return 'Neutral'
|
|
@@ -21,9 +21,9 @@ def textblob_sentiment(text):
|
|
| 21 |
def vader_sentiment(text):
|
| 22 |
analyzer = SentimentIntensityAnalyzer()
|
| 23 |
scores = analyzer.polarity_scores(text)
|
| 24 |
-
if scores['compound'] > 0:
|
| 25 |
return 'Positive'
|
| 26 |
-
elif scores['compound'] < 0:
|
| 27 |
return 'Negative'
|
| 28 |
else:
|
| 29 |
return 'Neutral'
|
|
@@ -42,7 +42,13 @@ if st.button('Predict'):
|
|
| 42 |
st.write(f'Sentiment: {sentiment}')
|
| 43 |
else:
|
| 44 |
model = models[model_name]
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
def textblob_sentiment(text):
|
| 13 |
polarity = TextBlob(text).sentiment.polarity
|
| 14 |
+
if polarity > 0.2:
|
| 15 |
return 'Positive'
|
| 16 |
+
elif polarity < -0.2:
|
| 17 |
return 'Negative'
|
| 18 |
else:
|
| 19 |
return 'Neutral'
|
|
|
|
| 21 |
def vader_sentiment(text):
|
| 22 |
analyzer = SentimentIntensityAnalyzer()
|
| 23 |
scores = analyzer.polarity_scores(text)
|
| 24 |
+
if scores['compound'] > 0.5:
|
| 25 |
return 'Positive'
|
| 26 |
+
elif scores['compound'] < -0.5:
|
| 27 |
return 'Negative'
|
| 28 |
else:
|
| 29 |
return 'Neutral'
|
|
|
|
| 42 |
st.write(f'Sentiment: {sentiment}')
|
| 43 |
else:
|
| 44 |
model = models[model_name]
|
| 45 |
+
results = model(text, return_all_scores=True)
|
| 46 |
+
st.write('Results:')
|
| 47 |
+
for result in results:
|
| 48 |
+
label = result['label']
|
| 49 |
+
score = result['score']
|
| 50 |
+
if score > 0.2:
|
| 51 |
+
st.write(f'{label} (Score: {score:.2f})')
|
| 52 |
+
mixed_score = 1 - sum([r['score'] for r in results])
|
| 53 |
+
if mixed_score > 0.2:
|
| 54 |
+
st.write(f'Mixed (Score: {mixed_score:.2f})')
|