entregable3 / app.py
gubringa's picture
Create app.py
0ceefe3 verified
# 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)