File size: 1,535 Bytes
1ffa482
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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()