Spaces:
Runtime error
Runtime error
| from fastai.vision.all import * | |
| import gradio as gr | |
| from pathlib import Path | |
| # Rutas relativas dentro del Space | |
| path = Path("dataset") # la carpeta que subiste | |
| # Crear los DataLoaders desde las carpetas | |
| dls = ImageDataLoaders.from_folder( | |
| path, | |
| valid_pct=0.2, | |
| seed=42, | |
| item_tfms=Resize(224) | |
| ) | |
| # Cargar tu modelo .pth | |
| learn = vision_learner(dls, resnet34) | |
| learn.load("model_lab") # si lo guardaste en models/, usar "models/model_lab" | |
| labels = learn.dls.vocab # toma las clases automáticamente | |
| def predict(img): | |
| img = PILImage.create(img) | |
| _, _, probs = learn.predict(img) | |
| return {labels[i]: float(probs[i]) for i in range(len(labels))} | |
| demo = gr.Interface( | |
| fn=predict, | |
| inputs=gr.Image(type="filepath"), | |
| outputs=gr.Label(num_top_classes=3), | |
| title="Lab Utensils Classifier" | |
| ) | |
| demo.launch() | |