|
|
import gradio as gr |
|
|
from transformers import ( |
|
|
AutoModelForSequenceClassification, |
|
|
AutoTokenizer, |
|
|
TextClassificationPipeline |
|
|
) |
|
|
|
|
|
|
|
|
model = AutoModelForSequenceClassification.from_pretrained("alramil/Practica7MA") |
|
|
tokenizer = AutoTokenizer.from_pretrained("alramil/Practica7MA") |
|
|
|
|
|
|
|
|
classifier = TextClassificationPipeline( |
|
|
model=model, |
|
|
tokenizer=tokenizer, |
|
|
device=0 |
|
|
) |
|
|
|
|
|
def clasificar(texto): |
|
|
result = classifier(texto)[0] |
|
|
etiqueta = result['label'] |
|
|
puntuacion = result['score'] |
|
|
etiqueta_legible = 'Peligroso' if etiqueta in ['LABEL_0', '0'] else 'Seguro' |
|
|
return f"{etiqueta_legible} ({puntuacion:.2%} de confianza)" |
|
|
|
|
|
|
|
|
demo = gr.Interface( |
|
|
fn=clasificar, |
|
|
inputs=gr.Textbox(lines=3, placeholder="Escribe aquí tu texto"), |
|
|
outputs="text", |
|
|
title="Clasificador de Texto Peligroso", |
|
|
description="Detecta si un mensaje es seguro o peligroso usando tu modelo Practica7MA alojado en HF Hub." |
|
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
|
demo.launch() |
|
|
|