Rodrigo_Cobo commited on
Commit
98d2c0f
1 Parent(s): 10c55f7

fix jpeg error

Browse files
Files changed (1) hide show
  1. app.py +6 -7
app.py CHANGED
@@ -7,7 +7,7 @@ import numpy as np
7
  import matplotlib.pyplot as plt
8
  from PIL import Image
9
 
10
- def update(slider, img):
11
 
12
  if not os.path.exists('temp'):
13
  os.system('mkdir temp')
@@ -16,7 +16,7 @@ def update(slider, img):
16
 
17
  img.save(filename, "JPEG")
18
 
19
- model_type = "DPT_Hybrid"
20
  midas = torch.hub.load("intel-isl/MiDaS", model_type)
21
 
22
  device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
@@ -49,13 +49,8 @@ def update(slider, img):
49
 
50
  formatted = (output * 255 / np.max(output)).astype('uint8')
51
  out_im = Image.fromarray(formatted)
52
-
53
- #out_im = Image.fromarray(output)
54
  out_im.save("temp/image_depth.jpeg", "JPEG")
55
 
56
- #cv2.imwrite("temp/image_depth.jpeg", output)
57
- #plt.imsave("temp/image_depth.jpeg", output)
58
-
59
  return f'temp/image_depth.jpeg'
60
 
61
 
@@ -64,6 +59,10 @@ with gr.Blocks() as demo:
64
  gr.Markdown("Start typing below and then click **Run** to see the output.")
65
  inp = [gr.Slider(1,15, default = 2, label='StepCycles',step= 1)]
66
 
 
 
 
 
67
  with gr.Row():
68
  inp.append(gr.Image(type="pil", label="Input"))
69
  out = gr.Image(type="file", label="Output")
 
7
  import matplotlib.pyplot as plt
8
  from PIL import Image
9
 
10
+ def update(slider, model_type, img):
11
 
12
  if not os.path.exists('temp'):
13
  os.system('mkdir temp')
 
16
 
17
  img.save(filename, "JPEG")
18
 
19
+ #model_type = "DPT_Hybrid"
20
  midas = torch.hub.load("intel-isl/MiDaS", model_type)
21
 
22
  device = torch.device("cuda") if torch.cuda.is_available() else torch.device("cpu")
 
49
 
50
  formatted = (output * 255 / np.max(output)).astype('uint8')
51
  out_im = Image.fromarray(formatted)
 
 
52
  out_im.save("temp/image_depth.jpeg", "JPEG")
53
 
 
 
 
54
  return f'temp/image_depth.jpeg'
55
 
56
 
 
59
  gr.Markdown("Start typing below and then click **Run** to see the output.")
60
  inp = [gr.Slider(1,15, default = 2, label='StepCycles',step= 1)]
61
 
62
+ midas_models = ["DPT_Large","DPT_Hybrid","MiDaS_small"]
63
+
64
+ inp.append(gr.inputs.Dropdown(midas_models, default="MiDaS_small", label="Midas_model_type"))
65
+
66
  with gr.Row():
67
  inp.append(gr.Image(type="pil", label="Input"))
68
  out = gr.Image(type="file", label="Output")