Spaces:
Runtime error
Runtime error
| 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() | |