MarioGL commited on
Commit
f34f79d
·
verified ·
1 Parent(s): 2404ef6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -26
app.py CHANGED
@@ -1,35 +1,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
 
 
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