pagaliv commited on
Commit
1a1d7f3
verified
1 Parent(s): 6b093d4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -12
app.py CHANGED
@@ -1,16 +1,19 @@
1
  import gradio as gr
2
- from huggingface_hub import hf_hub_download
3
- import torch
4
- import pickle
5
 
6
- # Workaround para cargar el modelo
7
- model_path = hf_hub_download(repo_id="pagaliv/futurama-character-classifier", filename="model.pkl")
8
- modelo = torch.load(model_path, pickle_module=pickle, map_location='cpu')
9
 
10
- def clasificar(img):
11
- # Preprocesa la imagen como lo hac铆as durante el entrenamiento
12
- # (Aqu铆 necesitar谩s tu l贸gica personalizada)
13
- pred = modelo.predict(img)
14
- return pred
 
 
 
15
 
16
- gr.Interface(fn=clasificar, inputs="image", outputs="label").launch()
 
1
  import gradio as gr
2
+ from fastai.vision.all import *
3
+ from huggingface_hub import from_pretrained_fastai
4
+ modelo = from_pretrained_fastai("pagaliv/futurama-character-classifier")
5
 
6
+ def clasificar_imagen(img):
7
+ pred, _, prob = modelo.predict(img)
8
+ return {modelo.dls.vocab[i]: float(prob[i]) for i in range(len(prob))}
9
 
10
+ # Interfaz
11
+ iface = gr.Interface(
12
+ fn=clasificar_imagen,
13
+ inputs=gr.Image(type="pil"),
14
+ outputs=gr.Label(num_top_classes=3),
15
+ examples=["BENDER.jpg","BENDER2.jpg", "FRY.jpg","FRY2.jpg","LEELA.jpg","LEELA2.jpg"], # Aseg煤rate de subir estos archivos
16
+ title="Clasificador de Futurama"
17
+ )
18
 
19
+ iface.launch()