File size: 1,109 Bytes
a1c86af
a3d448f
 
 
 
 
a1c86af
a3d448f
1cbdf07
 
a1c86af
a3d448f
 
 
 
 
 
a1c86af
 
 
 
 
 
 
 
a3d448f
a1c86af
 
 
 
 
1cbdf07
a1c86af
 
 
a3d448f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import gradio as gr
from transformers import (
    AutoModelForSequenceClassification,
    AutoTokenizer,
    TextClassificationPipeline
)

# 1) Carga manual del modelo y el tokenizador
model = AutoModelForSequenceClassification.from_pretrained("alramil/Practica7MA")
tokenizer = AutoTokenizer.from_pretrained("alramil/Practica7MA")

# 2) Construye la pipeline
classifier = TextClassificationPipeline(
    model=model,
    tokenizer=tokenizer,
    device=0  # GPU si está disponible
)

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)"

# 3) Interfaz Gradio
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()