gcmarian's picture
Create app.py
1ffa482 verified
import gradio as gr
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
# Configuraci贸n de VADER
analyzer = SentimentIntensityAnalyzer()
# Funci贸n para analizar el sentimiento
def analyze_sentiment(text):
if text:
scores = analyzer.polarity_scores(text)
sentiment = "Positive" if scores["compound"] > 0 else "Negative" if scores["compound"] < 0 else "Neutral"
return f"Sentiment: {sentiment}\nDetails: {scores}"
else:
return "Please enter valid text."
# Frases predefinidas
positive_examples = ["I absolutely love this product, it's amazing!", "This is the best day of my life!"]
negative_examples = ["I hate this experience, it's terrible.", "This is the worst product I've ever tried."]
neutral_examples = ["The package arrived on time.", "It was an ordinary day, nothing special."]
# Crear la interfaz con Gradio
interface = gr.Interface(
fn=analyze_sentiment,
inputs=gr.Textbox(lines=3, placeholder="Type a text to analyze...", label="Enter Text"),
outputs="text",
examples=[ # Botones de frases predefinidas
[positive_examples[0]],
[positive_examples[1]],
[negative_examples[0]],
[negative_examples[1]],
[neutral_examples[0]],
[neutral_examples[1]],
],
title="Sentiment Analysis",
description="Enter text in English to analyze its sentiment (positive, negative, or neutral). You can also try the predefined examples below.",
theme=gr.themes.Soft(),
)
# Lanzar la app
interface.launch()