|
|
from transformers import pipeline |
|
|
import gradio as gr |
|
|
|
|
|
classifier = pipeline("sentiment-analysis", model="cardiffnlp/twitter-roberta-base-sentiment") |
|
|
|
|
|
def analizar_sentimiento(texto): |
|
|
resultado = classifier(texto) |
|
|
|
|
|
|
|
|
etiqueta = resultado[0]['label'] |
|
|
puntuacion = resultado[0]['score'] |
|
|
|
|
|
|
|
|
if etiqueta == "LABEL_0": |
|
|
sentimiento = "negativo" |
|
|
elif etiqueta == "LABEL_1": |
|
|
sentimiento = "neutro" |
|
|
elif etiqueta == "LABEL_2": |
|
|
sentimiento = "positivo" |
|
|
else: |
|
|
sentimiento = etiqueta |
|
|
|
|
|
|
|
|
return f"El comentario es {sentimiento}. En un {puntuacion*100:.2f}%" |
|
|
|
|
|
|
|
|
demo = gr.Interface( |
|
|
fn=analizar_sentimiento, |
|
|
inputs=gr.Textbox(lines=5, placeholder="Escribe un texto en ingles aquí..."), |
|
|
outputs="text", |
|
|
title="Análisis de Sentimientos", |
|
|
description="Introduce un texto en ingles y obtén el sentimiento analizado y un porcentaje que indica cuanto es." |
|
|
) |
|
|
|
|
|
demo.launch() |