Pontonkid's picture
Create app.py
eca4855
import nltk
from nltk.sentiment import SentimentIntensityAnalyzer
# Download the vader_lexicon resource
nltk.download('vader_lexicon')
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.."
analyzer = SentimentIntensityAnalyzer()
scores = analyzer.polarity_scores(text)
if scores['compound'] >= 0.05:
print("Positive Sentiment")
elif scores['compound'] <= -0.05:
print("Negative Sentiment")
else:
print("Neutral Sentiment")
import gradio as gr
import nltk
from nltk.sentiment import SentimentIntensityAnalyzer
nltk.download('vader_lexicon')
analyzer = SentimentIntensityAnalyzer()
def analyze_sentiment(text):
scores = analyzer.polarity_scores(text)
if scores['compound'] >= 0.5:
sentiment = "Very Positive πŸ˜ƒ"
elif scores['compound'] > 0 and scores['compound'] < 0.5:
sentiment = "Positive πŸ™‚"
elif scores['compound'] == 0:
sentiment = "Neutral 😐"
elif scores['compound'] > -0.5 and scores['compound'] < 0:
sentiment = "Negative πŸ™"
elif scores['compound'] <= -0.5:
sentiment = "Very Negative 😠"
elif "racist" in text.lower():
sentiment = "Racist 🀬"
elif "annoying" in text.lower():
sentiment = "Annoying πŸ˜’"
elif "boring" in text.lower():
sentiment = "Boring 😴"
else:
sentiment = "Unknown πŸ˜•"
return sentiment, text
iface = gr.Interface(fn=analyze_sentiment,
inputs=gr.inputs.Textbox(label="Enter Text Here"),
outputs=[gr.outputs.Textbox(label="Sentiment"),
gr.outputs.Textbox(label="Input Text")],
title="Sentiment Analysis",
description="Enter a sentence and get the sentiment analysis result.")
iface.launch()