ameerazam08 commited on
Commit
ea486b4
1 Parent(s): b3ca2c1

Create gradio_depth_pred.py

Browse files
Files changed (1) hide show
  1. gradio_depth_pred.py +28 -0
gradio_depth_pred.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from utils import colorize
3
+ from PIL import Image
4
+ import tempfile
5
+
6
+ def predict_depth(model, image):
7
+ depth = model.infer_pil(image)
8
+ return depth
9
+
10
+ def create_demo(model):
11
+ gr.Markdown("### Depth Prediction demo")
12
+ with gr.Row():
13
+ input_image = gr.Image(label="Input Image", type='pil', elem_id='img-display-input').style(height="auto")
14
+ depth_image = gr.Image(label="Depth Map", elem_id='img-display-output')
15
+ raw_file = gr.File(label="16-bit raw depth, multiplier:256")
16
+ submit = gr.Button("Submit")
17
+
18
+ def on_submit(image):
19
+ depth = predict_depth(model, image)
20
+ colored_depth = colorize(depth, cmap='gray_r')
21
+ tmp = tempfile.NamedTemporaryFile(suffix='.png', delete=False)
22
+ raw_depth = Image.fromarray((depth*256).astype('uint16'))
23
+ raw_depth.save(tmp.name)
24
+ return [colored_depth, tmp.name]
25
+
26
+ submit.click(on_submit, inputs=[input_image], outputs=[depth_image, raw_file])
27
+ examples = gr.Examples(examples=["examples/person_1.jpeg", "examples/person_2.jpeg", "examples/person-leaves.png", "examples/living-room.jpeg"],
28
+ inputs=[input_image])