Spaces:
Sleeping
Sleeping
Commit
·
5c33f22
1
Parent(s):
c67c01a
Modificación para usar DistilBETO
Browse files
app.py
CHANGED
@@ -1,25 +1,32 @@
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
-
# Cargar el modelo DistilBETO
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
|
10 |
-
|
11 |
-
def analyze_sentiment(text):
|
12 |
-
results = sentiment_analysis(text)
|
13 |
-
return f"Label: {results[0]['label']}, Score: {results[0]['score']}"
|
14 |
|
15 |
-
#
|
16 |
demo = gr.Interface(
|
17 |
-
fn=
|
18 |
inputs="text",
|
19 |
outputs="text",
|
20 |
title="Análisis de Sentimientos con DistilBETO",
|
21 |
-
description="Ingrese un texto en español para analizar su sentimiento."
|
22 |
)
|
23 |
|
24 |
-
# Lanzar la aplicación
|
25 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
from transformers import pipeline
|
3 |
|
4 |
+
# Cargar el modelo DistilBETO para análisis de sentimientos
|
5 |
+
modelo = "finiteautomata/beto-sentiment-analysis"
|
6 |
+
sentiment_analysis = pipeline("sentiment-analysis", model=modelo, tokenizer=modelo)
|
7 |
+
|
8 |
+
def analizar_sentimiento(texto):
|
9 |
+
resultado = sentiment_analysis(texto)[0]
|
10 |
+
label = resultado['label']
|
11 |
+
score = resultado['score']
|
12 |
+
|
13 |
+
# Determinar si es positivo, negativo o neutro
|
14 |
+
if label == 'NEG':
|
15 |
+
sentimiento = "Negativo"
|
16 |
+
elif label == 'NEU':
|
17 |
+
sentimiento = "Neutro"
|
18 |
+
else:
|
19 |
+
sentimiento = "Positivo"
|
20 |
|
21 |
+
return f"Sentimiento: {sentimiento}, Confianza: {score:.2f}"
|
|
|
|
|
|
|
22 |
|
23 |
+
# Interfaz Gradio
|
24 |
demo = gr.Interface(
|
25 |
+
fn=analizar_sentimiento,
|
26 |
inputs="text",
|
27 |
outputs="text",
|
28 |
title="Análisis de Sentimientos con DistilBETO",
|
29 |
+
description="Ingrese un texto en español para analizar su sentimiento usando DistilBETO."
|
30 |
)
|
31 |
|
|
|
32 |
demo.launch()
|