Spaces:
Build error
Build error
Download app.py from Jhoeel/sentimentAnalysis: direct link, hf CLI and curl.
- Browser
- Download file 1.1 kB
-
https://huggingface.co/spaces/Jhoeel/sentimentAnalysis/resolve/main/app.py
- Command line
-
hf download hf://spaces/Jhoeel/sentimentAnalysis/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Jhoeel/sentimentAnalysis/resolve/main/app.py
1.1 kB
| # 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() | |