|
|
import gradio as gr |
|
|
from transformers import pipeline |
|
|
import torch |
|
|
|
|
|
|
|
|
REPO_ID = "alramil/Practica9" |
|
|
|
|
|
|
|
|
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) |