File size: 1,080 Bytes
d46a795
4f0f380
3c7759e
 
69f4167
 
 
 
e73cec9
 
4f0f380
e73cec9
4f0f380
f055300
 
 
4f0f380
 
f055300
e73cec9
 
 
4f0f380
 
 
 
 
e73cec9
 
 
 
f055300
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
from pathlib import Path

import gradio as gr
from huggingface_hub import from_pretrained_fastai
from fastai.vision.all import *
from fastai.vision.widgets import *
from fastdownload import download_url


# Cargar modelo de clasificaci贸n de im谩genes desde Hugging Face
learn = from_pretrained_fastai("AlejandroOSM1/Clasificador_de_camiones_Definitivo_Resnet18")

# Obtener etiquetas del modelo
labels = learn.dls.vocab

def predict(img):
    img = PILImage.create(img)  # Convertir imagen a formato FastAI
    pred, pred_idx, probs = learn.predict(img)
    return {labels[i]: float(probs[i]) for i in range(len(labels))}

# Crear la interfaz con Gradio
interface = gr.Interface(
    fn=predict,  # Se usaba "classify_image", pero la funci贸n definida es "predict"
    inputs=gr.Image(type="pil"),
    outputs=gr.Label(num_top_classes=3),  # Mostrar el top 3 de clases
    title="Clasificador de Camiones",
    description="Sube una imagen y el modelo la clasificar谩 en diferentes tipos de camiones."
)

# Lanzar la aplicaci贸n
if __name__ == "__main__":
    interface.launch()