alramil commited on
Commit
a1c86af
·
verified ·
1 Parent(s): 83c9b44

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Carga el pipeline de clasificación desde Hugging Face Hub
5
+ def get_classifier():
6
+ return pipeline(
7
+ task="text-classification",
8
+ model="alramil/Practica7", # tu modelo alojado
9
+ device=0 # usa GPU si está disponible en el Space
10
+ )
11
+
12
+ classifier = get_classifier()
13
+
14
+ def clasificar(texto):
15
+ result = classifier(texto)[0]
16
+ etiqueta = result['label']
17
+ puntuacion = result['score']
18
+ # Ajusta el formato según tus etiquetas (por ejemplo, 'LABEL_0' vs. 'Peligroso')
19
+ etiqueta_legible = 'Peligroso' if etiqueta in ['LABEL_0', '0'] else 'Seguro'
20
+ return f"{etiqueta_legible} ({puntuacion:.2%} de confianza)"
21
+
22
+ # Interfaz Gradio
23
+ demo = gr.Interface(
24
+ fn=clasificar,
25
+ inputs=gr.Textbox(lines=3, placeholder="Escribe aquí tu texto"),
26
+ outputs="text",
27
+ title="Clasificador de Texto Peligroso",
28
+ description="Detecta si un mensaje es seguro o peligroso usando tu modelo Practica7 alojado en Hugging Face Hub."
29
+ )
30
+
31
+ if __name__ == "__main__":
32
+ demo.launch()