Spaces:
Runtime error
Runtime error
Subiendo modelo y app de Pokémon
Browse files
app.py
CHANGED
|
@@ -1,36 +1,38 @@
|
|
| 1 |
|
| 2 |
from fastai.vision.all import *
|
| 3 |
import gradio as gr
|
| 4 |
-
import sys
|
| 5 |
|
| 6 |
-
# 1.
|
| 7 |
-
def get_x(i): return None
|
| 8 |
def get_y(i): return None
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
# Esto soluciona el error UnboundLocalError al cargar el pickle
|
| 12 |
import __main__
|
| 13 |
__main__.get_x = get_x
|
| 14 |
__main__.get_y = get_y
|
| 15 |
|
| 16 |
-
# 2.
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
| 22 |
|
| 23 |
def predict(img):
|
| 24 |
img = PILImage.create(img)
|
| 25 |
pred, pred_idx, probs = learn.predict(img)
|
| 26 |
-
return {
|
| 27 |
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
inputs=gr.Image(),
|
| 32 |
-
outputs=gr.Label(num_top_classes=3),
|
| 33 |
-
title="Detector de Tipos Pokémon"
|
| 34 |
-
)
|
| 35 |
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
|
| 2 |
from fastai.vision.all import *
|
| 3 |
import gradio as gr
|
|
|
|
| 4 |
|
| 5 |
+
# 1. Definiciones de placeholders para que coincidan con el export
|
| 6 |
+
def get_x(i): return None
|
| 7 |
def get_y(i): return None
|
| 8 |
|
| 9 |
+
# Forzar la visibilidad en el módulo principal para el unpickler
|
|
|
|
| 10 |
import __main__
|
| 11 |
__main__.get_x = get_x
|
| 12 |
__main__.get_y = get_y
|
| 13 |
|
| 14 |
+
# 2. Carga del modelo
|
| 15 |
+
# Si falla aquí, el problema es que el archivo .pkl está corrupto o mal subido con LFS
|
| 16 |
+
try:
|
| 17 |
+
learn = load_learner('modelo_pokemon.pkl')
|
| 18 |
+
labels = learn.dls.vocab
|
| 19 |
+
except Exception as e:
|
| 20 |
+
print(f"Error cargando el modelo: {e}")
|
| 21 |
+
raise e
|
| 22 |
|
| 23 |
def predict(img):
|
| 24 |
img = PILImage.create(img)
|
| 25 |
pred, pred_idx, probs = learn.predict(img)
|
| 26 |
+
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 27 |
|
| 28 |
+
# 3. Interfaz de Gradio
|
| 29 |
+
title = "Detector de Tipos Pokémon"
|
| 30 |
+
description = "Sube una imagen para identificar el tipo elemental del Pokémon."
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
+
gr.Interface(
|
| 33 |
+
fn=predict,
|
| 34 |
+
inputs=gr.Image(),
|
| 35 |
+
outputs=gr.Label(num_top_classes=3),
|
| 36 |
+
title=title,
|
| 37 |
+
description=description
|
| 38 |
+
).launch()
|