| import gradio as gr |
| from transformers import pipeline |
|
|
| |
| classifier = pipeline( |
| "sentiment-analysis", |
| model="nlptown/bert-base-multilingual-uncased-sentiment" |
| ) |
|
|
| def mapear_sentimiento(resultado): |
| etiqueta = resultado[0]["label"] |
| estrellas = int(etiqueta.split()[0]) |
|
|
| if estrellas <= 2: |
| return "Negativo" |
| elif estrellas == 3: |
| return "Neutro" |
| else: |
| return "Positivo" |
|
|
| def analizar_sentimiento(texto): |
| resultado = classifier(texto) |
| return mapear_sentimiento(resultado) |
|
|
| demo = gr.Interface( |
| fn=analizar_sentimiento, |
| inputs=gr.Textbox(lines=3, placeholder="Escribe un texto en español..."), |
| outputs="text", |
| title="Clasificador de Sentimientos en Español" |
| ) |
|
|
| demo.launch() |