Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import nltk
|
| 2 |
+
from nltk.sentiment import SentimentIntensityAnalyzer
|
| 3 |
+
|
| 4 |
+
# Download the vader_lexicon resource
|
| 5 |
+
nltk.download('vader_lexicon')
|
| 6 |
+
|
| 7 |
+
text = "I absolutely loved this movie! The acting was superb, the plot was engaging, and the cinematography was stunning. I would highly recommend it to anyone looking for a great film to watch.."
|
| 8 |
+
analyzer = SentimentIntensityAnalyzer()
|
| 9 |
+
scores = analyzer.polarity_scores(text)
|
| 10 |
+
if scores['compound'] >= 0.05:
|
| 11 |
+
print("Positive Sentiment")
|
| 12 |
+
elif scores['compound'] <= -0.05:
|
| 13 |
+
print("Negative Sentiment")
|
| 14 |
+
else:
|
| 15 |
+
print("Neutral Sentiment")
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
import gradio as gr
|
| 19 |
+
import nltk
|
| 20 |
+
from nltk.sentiment import SentimentIntensityAnalyzer
|
| 21 |
+
|
| 22 |
+
nltk.download('vader_lexicon')
|
| 23 |
+
|
| 24 |
+
analyzer = SentimentIntensityAnalyzer()
|
| 25 |
+
|
| 26 |
+
def analyze_sentiment(text):
|
| 27 |
+
scores = analyzer.polarity_scores(text)
|
| 28 |
+
if scores['compound'] >= 0.5:
|
| 29 |
+
sentiment = "Very Positive π"
|
| 30 |
+
elif scores['compound'] > 0 and scores['compound'] < 0.5:
|
| 31 |
+
sentiment = "Positive π"
|
| 32 |
+
elif scores['compound'] == 0:
|
| 33 |
+
sentiment = "Neutral π"
|
| 34 |
+
elif scores['compound'] > -0.5 and scores['compound'] < 0:
|
| 35 |
+
sentiment = "Negative π"
|
| 36 |
+
elif scores['compound'] <= -0.5:
|
| 37 |
+
sentiment = "Very Negative π "
|
| 38 |
+
elif "racist" in text.lower():
|
| 39 |
+
sentiment = "Racist π€¬"
|
| 40 |
+
elif "annoying" in text.lower():
|
| 41 |
+
sentiment = "Annoying π"
|
| 42 |
+
elif "boring" in text.lower():
|
| 43 |
+
sentiment = "Boring π΄"
|
| 44 |
+
else:
|
| 45 |
+
sentiment = "Unknown π"
|
| 46 |
+
return sentiment, text
|
| 47 |
+
|
| 48 |
+
iface = gr.Interface(fn=analyze_sentiment,
|
| 49 |
+
inputs=gr.inputs.Textbox(label="Enter Text Here"),
|
| 50 |
+
outputs=[gr.outputs.Textbox(label="Sentiment"),
|
| 51 |
+
gr.outputs.Textbox(label="Input Text")],
|
| 52 |
+
title="Sentiment Analysis",
|
| 53 |
+
description="Enter a sentence and get the sentiment analysis result.")
|
| 54 |
+
|
| 55 |
+
iface.launch()
|
| 56 |
+
|