MSaadTariq commited on
Commit
aea53b6
·
verified ·
1 Parent(s): 86a44df

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -0
app.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+
3
+ depth_estimator = pipeline(task="depth-estimation",
4
+ model="Intel/dpt-hybrid-midas")
5
+
6
+ import gradio as gr
7
+ from transformers import Pipeline
8
+
9
+ def launch(input_image):
10
+ out = depth_estimator(input_image)
11
+
12
+ # resize the prediction
13
+ prediction = torch.nn.functional.interpolate(
14
+ out["predicted_depth"].unsqueeze(1),
15
+ size=input_image.size[::-1],
16
+ mode="bicubic",
17
+ align_corners=False,
18
+ )
19
+
20
+ # normalize the prediction
21
+ output = prediction.squeeze().numpy()
22
+ formatted = (output * 255 / np.max(output)).astype("uint8")
23
+ depth = Image.fromarray(formatted)
24
+ return depth
25
+
26
+ iface = gr.Interface(launch,
27
+ inputs=[gr.Image(label="Upload image", type="pil")],
28
+ outputs=[gr.Image(label="Depth Map", type="pil")],
29
+ title="DepthSense",
30
+ description="Dive into the unseen depths of your images! Simply upload and let DepthSense reveal a whole new dimension of your visuals, instantly" )
31
+
32
+ iface.launch()