Spaces:
Running
Running
souvikmaji22
commited on
Update app.py
Browse files
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 |
-
|
9 |
-
|
|
|
10 |
|
11 |
# resize the prediction
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
|
19 |
# normalize the prediction
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
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()
|