Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,35 @@
|
|
1 |
-
from huggingface_hub import from_pretrained_fastai
|
2 |
-
import gradio as gr
|
3 |
from fastai.vision.all import *
|
|
|
4 |
|
|
|
|
|
5 |
|
|
|
|
|
6 |
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
-
|
10 |
-
|
|
|
11 |
|
12 |
-
#
|
13 |
def predict(img):
|
14 |
-
|
15 |
-
pred,pred_idx,probs = learner.predict(img)
|
16 |
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
17 |
-
|
18 |
-
#
|
19 |
-
gr.Interface(
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
21 |
|
|
|
|
|
|
|
1 |
from fastai.vision.all import *
|
2 |
+
import gradio as gr
|
3 |
|
4 |
+
# 1. Carga las clases
|
5 |
+
labels = ['okabe', 'kurisu'] # ← Ajusta con tus etiquetas reales
|
6 |
|
7 |
+
# 2. Reconstruye los data loaders (usa imagen ficticia para construirlos)
|
8 |
+
def label_func(fname): return 'okabe' # dummy label
|
9 |
|
10 |
+
dls = ImageDataLoaders.from_name_func(
|
11 |
+
Path('.'),
|
12 |
+
get_image_files('.'),
|
13 |
+
label_func=label_func,
|
14 |
+
item_tfms=Resize(224),
|
15 |
+
bs=1 # batch size pequeño, no se usará en producción
|
16 |
+
)
|
17 |
|
18 |
+
# 3. Reconstruye el modelo (usa tu arquitectura real si es distinta)
|
19 |
+
learn = cnn_learner(dls, resnet34)
|
20 |
+
learn.load('model_weights') # Asegúrate de subir este archivo .pth a tu repo HF
|
21 |
|
22 |
+
# 4. Predicción
|
23 |
def predict(img):
|
24 |
+
pred, pred_idx, probs = learn.predict(img)
|
|
|
25 |
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
26 |
+
|
27 |
+
# 5. UI
|
28 |
+
gr.Interface(
|
29 |
+
fn=predict,
|
30 |
+
inputs=gr.Image(),
|
31 |
+
outputs=gr.Label(num_top_classes=3),
|
32 |
+
examples=['kurisu.jpg', 'okabe.jpg']
|
33 |
+
).launch(share=False)
|
34 |
+
|
35 |
|