AlejandrOSM1 commited on
Commit
882f5b8
verified
1 Parent(s): a06d70c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -17
app.py CHANGED
@@ -1,28 +1,29 @@
1
 
2
- from huggingface_hub import from_pretrained_fastai
 
3
  from fastai.vision.all import *
 
4
 
5
- from huggingface_hub import login, from_pretrained_fastai
6
 
7
- # Cargar el modelo
8
  learn = from_pretrained_fastai("AlejandrOSM1/Clasificador_de_camiones_Definitivo_Resnet18")
9
- # Obtener etiquetas del modelo
10
  labels = learn.dls.vocab
11
 
 
12
  def predict(img):
13
- img = PILImage.create(img) # Convertir imagen a formato FastAI
14
  pred, pred_idx, probs = learn.predict(img)
15
  return {labels[i]: float(probs[i]) for i in range(len(labels))}
16
 
17
- # Crear la interfaz con Gradio
18
- interface = gr.Interface(
19
- fn=predict, # Se usaba "classify_image", pero la funci贸n definida es "predict"
20
- inputs=gr.Image(type="pil"),
21
- outputs=gr.Label(num_top_classes=3), # Mostrar el top 3 de clases
22
- title="Clasificador de Camiones",
23
- description="Sube una imagen y el modelo la clasificar谩 en diferentes tipos de camiones."
24
- )
25
-
26
- # Lanzar la aplicaci贸n
27
- if __name__ == "__main__":
28
- interface.launch()
 
 
1
 
2
+
3
+ import gradio as gr
4
  from fastai.vision.all import *
5
+ from huggingface_hub import from_pretrained_fastai
6
 
 
7
 
 
8
  learn = from_pretrained_fastai("AlejandrOSM1/Clasificador_de_camiones_Definitivo_Resnet18")
 
9
  labels = learn.dls.vocab
10
 
11
+
12
  def predict(img):
13
+ img = PILImage.create(img)
14
  pred, pred_idx, probs = learn.predict(img)
15
  return {labels[i]: float(probs[i]) for i in range(len(labels))}
16
 
17
+
18
+ title = "Bad truck classifier"
19
+ description = "Just upload a truck"
20
+
21
+
22
+ gr.Interface(
23
+ fn=predict,
24
+ inputs=gr.Image(),
25
+ outputs=gr.Label(num_top_classes=10),
26
+ title=title,
27
+ description=description,
28
+ examples=examples,
29
+ ).launch()