rugarce commited on
Commit
661f9e9
verified
1 Parent(s): 7411d7f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -3
app.py CHANGED
@@ -3,15 +3,30 @@ import torch
3
  import numpy as np
4
  from PIL import Image
5
  from huggingface_hub import hf_hub_download
 
6
 
7
- # Descargar modelo TorchScript
 
 
 
 
 
 
 
 
 
 
 
8
  REPO_ID = "rugarce/model_practica3"
9
  FILENAME = "model.pkl"
10
 
11
  model_path = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
12
- model = torch.jit.load(model_path, map_location="cpu")
 
 
13
  model.eval()
14
 
 
15
  def predict(image):
16
  image = image.resize((640,480))
17
  image = np.array(image).astype(np.float32) / 255.0
@@ -30,4 +45,4 @@ demo = gr.Interface(
30
  title="Segmentaci贸n U-Net",
31
  )
32
 
33
- demo.launch()
 
3
  import numpy as np
4
  from PIL import Image
5
  from huggingface_hub import hf_hub_download
6
+ from fastai.vision.all import *
7
 
8
+ # --- Clases dummy necesarias para deserializar ---
9
+ class TargetMaskConvertTransform(ItemTransform):
10
+ def encodes(self, x): return x
11
+
12
+ class SegmentationAlbumentationsTransform(ItemTransform):
13
+ def __init__(self, aug=None): pass
14
+ def encodes(self, x): return x
15
+
16
+ def get_y_fn(x): return x
17
+ def ParentSplitter(x): return x
18
+
19
+ # --- Descargar modelo ---
20
  REPO_ID = "rugarce/model_practica3"
21
  FILENAME = "model.pkl"
22
 
23
  model_path = hf_hub_download(repo_id=REPO_ID, filename=FILENAME)
24
+
25
+ learn = load_learner(model_path, cpu=True)
26
+ model = learn.model
27
  model.eval()
28
 
29
+ # --- Inferencia simple ---
30
  def predict(image):
31
  image = image.resize((640,480))
32
  image = np.array(image).astype(np.float32) / 255.0
 
45
  title="Segmentaci贸n U-Net",
46
  )
47
 
48
+ demo.launch()