File size: 1,142 Bytes
0ceefe3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
# app.py
from fastai.text.all import *
import gradio as gr
from huggingface_hub import hf_hub_download


REPO_ID = "gubringa/learnClass"
MODEL_FILENAME = "model.pkl"

# Descargar y cargar el modelo
try:
    model_path = hf_hub_download(repo_id=REPO_ID, filename=MODEL_FILENAME)
    learn = load_learner(model_path)
    print(f"Modelo cargado correctamente desde: {model_path}")
except Exception as e:
    print(f"ERROR: No se pudo cargar el modelo. Detalles: {e}")
    learn = None

# Funci贸n para hacer predicciones
def classify_text(text):
    if learn is None:
        return "Error: Modelo no cargado. Por favor, revisa los logs del Space."
    pred, pred_idx, probs = learn.predict(text)
    return f"Predicci贸n: **{pred}** (Confianza: {probs[pred_idx].item():.4f})"

# Configuraci贸n de la interfaz Gradio
iface = gr.Interface(
    fn=classify_text,
    inputs=gr.Textbox(lines=5, label="Introduce tu texto aqu铆"),
    outputs="text",
    title="Clasificador de Texto ULMFit",
    description="Este Space utiliza un modelo de clasificaci贸n de texto ULMFit entrenado con Fastai.",
    theme="huggingface"
)

iface.launch(share=False)