Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,40 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer
|
3 |
+
|
4 |
+
# Configuraci贸n de VADER
|
5 |
+
analyzer = SentimentIntensityAnalyzer()
|
6 |
+
|
7 |
+
# Funci贸n para analizar el sentimiento
|
8 |
+
def analyze_sentiment(text):
|
9 |
+
if text:
|
10 |
+
scores = analyzer.polarity_scores(text)
|
11 |
+
sentiment = "Positive" if scores["compound"] > 0 else "Negative" if scores["compound"] < 0 else "Neutral"
|
12 |
+
return f"Sentiment: {sentiment}\nDetails: {scores}"
|
13 |
+
else:
|
14 |
+
return "Please enter valid text."
|
15 |
+
|
16 |
+
# Frases predefinidas
|
17 |
+
positive_examples = ["I absolutely love this product, it's amazing!", "This is the best day of my life!"]
|
18 |
+
negative_examples = ["I hate this experience, it's terrible.", "This is the worst product I've ever tried."]
|
19 |
+
neutral_examples = ["The package arrived on time.", "It was an ordinary day, nothing special."]
|
20 |
+
|
21 |
+
# Crear la interfaz con Gradio
|
22 |
+
interface = gr.Interface(
|
23 |
+
fn=analyze_sentiment,
|
24 |
+
inputs=gr.Textbox(lines=3, placeholder="Type a text to analyze...", label="Enter Text"),
|
25 |
+
outputs="text",
|
26 |
+
examples=[ # Botones de frases predefinidas
|
27 |
+
[positive_examples[0]],
|
28 |
+
[positive_examples[1]],
|
29 |
+
[negative_examples[0]],
|
30 |
+
[negative_examples[1]],
|
31 |
+
[neutral_examples[0]],
|
32 |
+
[neutral_examples[1]],
|
33 |
+
],
|
34 |
+
title="Sentiment Analysis",
|
35 |
+
description="Enter text in English to analyze its sentiment (positive, negative, or neutral). You can also try the predefined examples below.",
|
36 |
+
theme=gr.themes.Soft(),
|
37 |
+
)
|
38 |
+
|
39 |
+
# Lanzar la app
|
40 |
+
interface.launch()
|