RanjithkumarPanjabikesan commited on
Commit
1b46a9b
1 Parent(s): 55461a2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ depth_estimator = pipeline(task="depth-estimation",
3
+ model="Intel/dpt-hybrid-midas")
4
+ import os
5
+ from PIL import Image
6
+ import torch
7
+ import numpy as np
8
+ import gradio as gr
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
+ # normalize the prediction
20
+ output = prediction.squeeze().numpy()
21
+ formatted = (output * 255 / np.max(output)).astype("uint8")
22
+ depth = Image.fromarray(formatted)
23
+ return depth
24
+ iface = gr.Interface(launch,
25
+ inputs=gr.Image(type='pil'),
26
+ outputs=gr.Image(type='pil'))
27
+ iface.launch()