Spaces:
Runtime error
Runtime error
| from fastai.vision.all import * | |
| import gradio as gr | |
| from pathlib import Path | |
| import zipfile | |
| import os | |
| # Extraer zip | |
| with zipfile.ZipFile("dataset.zip", 'r') as zip_ref: | |
| zip_ref.extractall(".") # crea dataset/ | |
| # Asegurarse de que existe la carpeta correcta | |
| dataset_path = Path("dataset") | |
| if not dataset_path.exists(): | |
| raise FileNotFoundError("La carpeta 'dataset' no existe después de descomprimir el zip. Revisa la estructura del zip.") | |
| # Crear DataLoaders | |
| dls = ImageDataLoaders.from_folder( | |
| dataset_path, | |
| valid_pct=0.2, | |
| seed=42, | |
| item_tfms=Resize(224) | |
| ) | |
| # Cargar modelo | |
| 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() | |