Spaces:
Runtime error
Runtime error
| from fastai.vision.all import * | |
| import gradio as gr | |
| from pathlib import Path | |
| # Montar Drive si quieres usar imágenes de Drive en la app (opcional) | |
| from google.colab import drive | |
| # drive.mount('/content/drive') # normalmente NO se monta en Hugging Face, solo local | |
| # Rutas relativas al espacio | |
| path = Path(".") # aquí se suben las carpetas de clases | |
| dls = ImageDataLoaders.from_folder( | |
| path, | |
| valid_pct=0.2, | |
| seed=42, | |
| item_tfms=Resize(224) | |
| ) | |
| learn = vision_learner(dls, resnet34) | |
| learn.load("model_lab") | |
| labels = learn.dls.vocab | |
| 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() | |