File size: 876 Bytes
f70a0a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
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()