gubringa commited on
Commit
0ceefe3
verified
1 Parent(s): 17f02de

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ from fastai.text.all import *
3
+ import gradio as gr
4
+ from huggingface_hub import hf_hub_download
5
+
6
+
7
+ REPO_ID = "gubringa/learnClass"
8
+ MODEL_FILENAME = "model.pkl"
9
+
10
+ # Descargar y cargar el modelo
11
+ try:
12
+ model_path = hf_hub_download(repo_id=REPO_ID, filename=MODEL_FILENAME)
13
+ learn = load_learner(model_path)
14
+ print(f"Modelo cargado correctamente desde: {model_path}")
15
+ except Exception as e:
16
+ print(f"ERROR: No se pudo cargar el modelo. Detalles: {e}")
17
+ learn = None
18
+
19
+ # Funci贸n para hacer predicciones
20
+ def classify_text(text):
21
+ if learn is None:
22
+ return "Error: Modelo no cargado. Por favor, revisa los logs del Space."
23
+ pred, pred_idx, probs = learn.predict(text)
24
+ return f"Predicci贸n: **{pred}** (Confianza: {probs[pred_idx].item():.4f})"
25
+
26
+ # Configuraci贸n de la interfaz Gradio
27
+ iface = gr.Interface(
28
+ fn=classify_text,
29
+ inputs=gr.Textbox(lines=5, label="Introduce tu texto aqu铆"),
30
+ outputs="text",
31
+ title="Clasificador de Texto ULMFit",
32
+ description="Este Space utiliza un modelo de clasificaci贸n de texto ULMFit entrenado con Fastai.",
33
+ theme="huggingface"
34
+ )
35
+
36
+ iface.launch(share=False)