Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,21 @@
|
|
| 1 |
-
from
|
| 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 |
-
|
| 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 |
-
|
| 19 |
-
|
| 20 |
-
learn.load('model_weights') # Asegúrate de subir este archivo .pth a tu repo HF
|
| 21 |
|
| 22 |
-
#
|
| 23 |
def predict(img):
|
| 24 |
-
|
|
|
|
| 25 |
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 26 |
-
|
| 27 |
-
#
|
| 28 |
-
gr.Interface(
|
| 29 |
-
|
| 30 |
-
inputs=gr.Image(),
|
| 31 |
-
outputs=gr.Label(num_top_classes=3),
|
| 32 |
-
examples=['kurisu.jpg', 'okabe.jpg']
|
| 33 |
-
).launch(share=False)
|
| 34 |
-
|
| 35 |
|
|
|
|
| 1 |
+
from huggingface_hub import from_pretrained_fastai
|
| 2 |
import gradio as gr
|
| 3 |
+
from fastai.vision.all import *
|
| 4 |
|
|
|
|
|
|
|
| 5 |
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
repo_id = "MarioGL/datasetSG"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
learner = from_pretrained_fastai(repo_id)
|
| 10 |
+
labels = learner.dls.vocab
|
|
|
|
| 11 |
|
| 12 |
+
# Definimos una función que se encarga de llevar a cabo las predicciones
|
| 13 |
def predict(img):
|
| 14 |
+
#img = PILImage.create(img)
|
| 15 |
+
pred,pred_idx,probs = learner.predict(img)
|
| 16 |
return {labels[i]: float(probs[i]) for i in range(len(labels))}
|
| 17 |
+
|
| 18 |
+
# Creamos la interfaz y la lanzamos.
|
| 19 |
+
gr.Interface(fn=predict, inputs=gr.Image(), outputs=gr.Label(num_top_classes=3),examples=['okabe.jpg','kurisu.jpg']).launch(share=False)
|
| 20 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|