Spaces:
Sleeping
Sleeping
File size: 1,103 Bytes
5927b5a 226cf35 5927b5a 3061ca9 226cf35 3061ca9 5927b5a b5bbbbd 226cf35 5927b5a 3061ca9 af6166c 3061ca9 b5bbbbd |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# Importa librerias
from transformers import pipeline
import gradio as gr
# Inicializa Modelo de Clasificación de Sentimientos
model_name = 'pysentimiento/robertuito-sentiment-analysis'
classifier = pipeline("text-classification", model=model_name)
def classify_text(text):
"""
Clasifica un texto como positivo, negativo o neutro utilizando un clasificador.
Args:
text (str): El texto a clasificar.
Returns:
str: La clasificación del texto, que puede ser "Positivo", "Negativo" o "Neutro".
"""
result = classifier(text)[0]['label']
if result == "POS":
return "Positivo"
elif result == "NEG":
return "Negativo"
else:
return "Neutro"
# Crea Interfaz Gradio
input_text = gr.inputs.Textbox(label="Texto a clasificar")
output_text = gr.outputs.Textbox(label="Sentimiento")
gr.Interface(fn=classify_text, inputs=input_text, outputs=output_text, examples=[
['Estoy feliz 🤗 de mostrarles un toolkit para Análisis de Sentimientos y otras tareas de SocialNLP'],
['Espero que no lo odien.'],
['Lo odiamos.']
]).launch()
|