Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Configuración del clasificador de sentimientos
|
5 |
+
classifier = pipeline(task="zero-shot-classification", model="facebook/bart-large-mnli")
|
6 |
+
|
7 |
+
def analyze_sentiment(text):
|
8 |
+
results = classifier(text, ["Positivo", "Negativo", "Neutro"], multi_label=True)
|
9 |
+
mx = max(results['scores'])
|
10 |
+
ind = results['scores'].index(mx)
|
11 |
+
result = results['labels'][ind]
|
12 |
+
|
13 |
+
return result
|
14 |
+
|
15 |
+
# Configuración de la interfaz de Gradio
|
16 |
+
demo = gr.Interface(
|
17 |
+
fn=analyze_sentiment,
|
18 |
+
inputs="Escribe tu comentario",
|
19 |
+
outputs="Sentimiento",
|
20 |
+
title="Análisis de Sentimientos"
|
21 |
+
)
|
22 |
+
|
23 |
+
# Lanzamiento de la interfaz
|
24 |
+
demo.launch(share=True)
|