souvikmaji22 commited on
Commit
4d5612a
·
verified ·
1 Parent(s): bef2e15

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ def launch(input_image):
5
+ out = depth_estimator(input_image)
6
+
7
+ # resize the prediction
8
+ prediction = torch.nn.functional.interpolate(
9
+ out["predicted_depth"].unsqueeze(1),
10
+ size=input_image.size[::-1],
11
+ mode="bicubic",
12
+ align_corners=False,
13
+ )
14
+
15
+ # normalize the prediction
16
+ output = prediction.squeeze().numpy()
17
+ formatted = (output * 255 / np.max(output)).astype("uint8")
18
+ depth = Image.fromarray(formatted)
19
+ return depth
20
+
21
+ iface = gr.Interface(launch,
22
+ inputs=gr.Image(type='pil'),
23
+ outputs=gr.Image(type='pil'))
24
+
25
+ iface.launch()