Spaces:
Running
Running
Download app.py from MikeDev1493/MTW410: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/spaces/MikeDev1493/MTW410/resolve/main/app.py
- Command line
-
hf download hf://spaces/MikeDev1493/MTW410/app.py
-
curl -L -o app.py https://huggingface.co/spaces/MikeDev1493/MTW410/resolve/main/app.py
1.26 kB
| import gradio as gr | |
| from transformers import pipeline | |
| # Modelo especializado en espa帽ol | |
| MODELO = "finiteautomata/beto-sentiment-analysis" | |
| # Cargar modelo y tokenizador | |
| clasificador = pipeline( | |
| "sentiment-analysis", | |
| model=MODELO, | |
| tokenizer=MODELO, | |
| device=-1 | |
| ) | |
| # Funci贸n de clasificaci贸n | |
| def analizar_sentimiento(texto): | |
| if not texto.strip(): | |
| return {} | |
| resultados = clasificador( | |
| texto, | |
| top_k=None, | |
| truncation=True, | |
| max_length=128 | |
| ) | |
| etiquetas = { | |
| "POS": "Positivo", | |
| "NEG": "Negativo", | |
| "NEU": "Neutral" | |
| } | |
| return { | |
| etiquetas.get(r["label"], r["label"]): r["score"] | |
| for r in resultados | |
| } | |
| # Interfaz gr谩fica | |
| demo = gr.Interface( | |
| fn=analizar_sentimiento, | |
| inputs=gr.Textbox( | |
| lines=4, | |
| label="Escribe una opini贸n" | |
| ), | |
| outputs=gr.Label( | |
| num_top_classes=3, | |
| label="Resultado" | |
| ), | |
| title="Analizador de sentimientos - MTW410", | |
| description="Inteligencia artificial con Hugging Face", | |
| examples=[ | |
| ["El servicio fue excelente"], | |
| ["No recomiendo este producto"], | |
| ["El pedido lleg贸 el martes"] | |
| ] | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |