Download app.py from alramil/Practica9: direct link, hf CLI and curl.
- Browser
- Download file 835 Bytes
-
https://huggingface.co/spaces/alramil/Practica9/resolve/main/app.py
- Command line
-
hf download hf://spaces/alramil/Practica9/app.py
-
curl -L -o app.py https://huggingface.co/spaces/alramil/Practica9/resolve/main/app.py
835 Bytes
| import gradio as gr | |
| from transformers import pipeline | |
| import torch | |
| # Reemplaza por tu identificador de modelo: | |
| REPO_ID = "alramil/Practica9" | |
| # Creamos pipeline cargando directamente del Hub | |
| classifier = pipeline( | |
| "text-classification", | |
| model=REPO_ID, | |
| tokenizer=REPO_ID, | |
| return_all_scores=True, | |
| device=0 if torch.cuda.is_available() else -1 | |
| ) | |
| def classify(text: str): | |
| outputs = classifier(text) | |
| return { d["label"]: float(d["score"]) for d in outputs } | |
| iface = gr.Interface( | |
| fn=classify, | |
| inputs=gr.Textbox(lines=5, placeholder="Escribe tu texto aquí…"), | |
| outputs=gr.Label(num_top_classes=3), | |
| title="🧠 Clasificador Practica9", | |
| description=f"Modelo cargado desde Hugging Face Hub: `{REPO_ID}`" | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch(server_name="0.0.0.0", server_port=7860) |