alramil commited on
Commit
da4b751
·
1 Parent(s): cfad999

Fix variable interpolation in app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -8
app.py CHANGED
@@ -3,12 +3,11 @@ import numpy as np
3
  from fastai.vision.all import load_learner, PILImage
4
  from huggingface_hub import hf_hub_download
5
 
6
- # Descargar y cargar export.pkl
7
- pkl = hf_hub_download(repo_id="${MODEL_REPO}", filename="export.pkl")
8
  learn = load_learner(pkl)
9
  learn.model.eval()
10
 
11
- # Paleta de colores para índices 0–4
12
  palette = np.array([
13
  [0,0,0], # fondo
14
  [0,128,0], # hojas
@@ -18,17 +17,15 @@ palette = np.array([
18
  ], dtype=np.uint8)
19
 
20
  def segment_image(img):
21
- # FastAI internamente hace resize, tensor y normalize
22
  pred,_,_ = learn.predict(PILImage.create(img))
23
- seg = np.array(pred) # H×W array de 0–4
24
  return palette[seg]
25
 
26
  demo = gr.Interface(
27
  fn=segment_image,
28
  inputs=gr.Image(type="pil", label="Sube imagen"),
29
- outputs=gr.Image(type="numpy", label="Máscara segmentada"),
30
- title="Segmentación de Racimos de Uva",
31
- description="Modelo U-Net entrenado con FastAI"
32
  )
33
 
34
  if __name__=="__main__":
 
3
  from fastai.vision.all import load_learner, PILImage
4
  from huggingface_hub import hf_hub_download
5
 
6
+ # Aquí se expande MODEL_REPO
7
+ pkl = hf_hub_download(repo_id="alramil/unet-segmentation-model", filename="export.pkl")
8
  learn = load_learner(pkl)
9
  learn.model.eval()
10
 
 
11
  palette = np.array([
12
  [0,0,0], # fondo
13
  [0,128,0], # hojas
 
17
  ], dtype=np.uint8)
18
 
19
  def segment_image(img):
 
20
  pred,_,_ = learn.predict(PILImage.create(img))
21
+ seg = np.array(pred)
22
  return palette[seg]
23
 
24
  demo = gr.Interface(
25
  fn=segment_image,
26
  inputs=gr.Image(type="pil", label="Sube imagen"),
27
+ outputs=gr.Image(type="numpy", label="Máscara"),
28
+ title="Segmentación Semántica de Racimos"
 
29
  )
30
 
31
  if __name__=="__main__":