Spaces:
Runtime error
Runtime error
File size: 742 Bytes
1fa1da9 c0926f4 a739378 4530bc5 919ec96 7954766 4530bc5 919ec96 7954766 4530bc5 7954766 8c8306b 4530bc5 a739378 7954766 79724de 7954766 |
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 |
import gradio as gr
from fastai.vision.all import *
import __main__
# 1. Definir las funciones que el modelo "busca" al abrirse.
# No necesitan hacer nada real, solo existir con el mismo nombre.
def get_x(i): return None
def get_y(i): return None
# 2. Inyectarlas en el módulo principal (esto es el truco clave)
__main__.get_x = get_x
__main__.get_y = get_y
# 3. Ahora sí, cargar el modelo
learn = load_learner('modelo_pokemon.pkl')
labels = learn.dls.vocab
def predict(img):
img = PILImage.create(img)
pred, pred_idx, probs = learn.predict(img)
return {labels[i]: float(probs[i]) for i in range(len(labels))}
# Interfaz de Gradio
gr.Interface(fn=predict, inputs=gr.Image(), outputs=gr.Label(num_top_classes=3)).launch()
|