souvikmaji22 commited on
Commit
09a22a3
1 Parent(s): 9eaf616

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -15
app.py CHANGED
@@ -1,29 +1,33 @@
1
  import gradio as gr
2
  from transformers import pipeline
 
 
 
3
 
4
 
5
  depth_estimator = pipeline(task="depth-estimation",
6
  model="Intel/dpt-hybrid-midas")
7
-
8
- def launch(input_image):
9
- out = depth_estimator(input_image)
 
10
 
11
  # resize the prediction
12
- prediction = torch.nn.functional.interpolate(
13
- out["predicted_depth"].unsqueeze(1),
14
- size=input_image.size[::-1],
15
- mode="bicubic",
16
- align_corners=False,
17
- )
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
 
25
- iface = gr.Interface(launch,
26
  inputs=gr.Image(type='pil'),
27
  outputs=gr.Image(type='pil'))
28
 
29
- iface.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
+ import torch
4
+ import numpy as np
5
+ from PIL import Image
6
 
7
 
8
  depth_estimator = pipeline(task="depth-estimation",
9
  model="Intel/dpt-hybrid-midas")
10
+ if __name__ == "__main__":
11
+
12
+ def launch(input_image):
13
+ out = depth_estimator(input_image)
14
 
15
  # resize the prediction
16
+ prediction = torch.nn.functional.interpolate(
17
+ out["predicted_depth"].unsqueeze(1),
18
+ size=input_image.size[::-1],
19
+ mode="bicubic",
20
+ align_corners=False,
21
+ )
22
 
23
  # normalize the prediction
24
+ output = prediction.squeeze().numpy()
25
+ formatted = (output * 255 / np.max(output)).astype("uint8")
26
+ depth = Image.fromarray(formatted)
27
+ return depth
28
 
29
+ iface = gr.Interface(launch,
30
  inputs=gr.Image(type='pil'),
31
  outputs=gr.Image(type='pil'))
32
 
33
+ iface.launch()