Akash Raj commited on
Commit
33de8a0
1 Parent(s): 22aa42f
Files changed (1) hide show
  1. app.py +4 -16
app.py CHANGED
@@ -1,7 +1,6 @@
1
  from transformers import pipeline
2
  from PIL import Image
3
  import gradio as gr
4
- import numpy as np
5
 
6
  # Load the Hugging Face depth estimation pipelines
7
  pipe_base = pipeline(task="depth-estimation", model="LiheYoung/depth-anything-base-hf")
@@ -16,19 +15,8 @@ def estimate_depths(image):
16
  depth_intel = pipe_intel(image)["depth"]
17
  depth_beit = pipe_beit(image)["depth"]
18
 
19
- # Normalize depths for visualization
20
- depth_base = normalize_depth(depth_base)
21
- depth_small = normalize_depth(depth_small)
22
- depth_intel = normalize_depth(depth_intel)
23
- depth_beit = normalize_depth(depth_beit)
24
-
25
  return depth_base, depth_small, depth_intel, depth_beit
26
 
27
- def normalize_depth(depth_map):
28
- # Normalize depth map values to range [0, 255] for visualization
29
- normalized_depth = ((depth_map - depth_map.min()) / (depth_map.max() - depth_map.min())) * 255
30
- return normalized_depth.astype(np.uint8)
31
-
32
  # Create a Gradio interface using Blocks
33
  with gr.Blocks() as iface:
34
  gr.Markdown("# Multi-Model Depth Estimation\nUpload an image to get depth estimation maps from multiple models.")
@@ -38,11 +26,11 @@ with gr.Blocks() as iface:
38
 
39
  with gr.Row():
40
  with gr.Column():
41
- output_base = gr.Image(type="numpy", label="LiheYoung/depth-anything-base-hf", interactive=False)
42
- output_small = gr.Image(type="numpy", label="LiheYoung/depth-anything-small-hf", interactive=False)
43
  with gr.Column():
44
- output_intel = gr.Image(type="numpy", label="Intel/dpt-swinv2-tiny-256", interactive=False)
45
- output_beit = gr.Image(type="numpy", label="Intel/dpt-beit-base-384", interactive=False)
46
 
47
  input_image.change(fn=estimate_depths, inputs=input_image, outputs=[output_base, output_small, output_intel, output_beit])
48
 
 
1
  from transformers import pipeline
2
  from PIL import Image
3
  import gradio as gr
 
4
 
5
  # Load the Hugging Face depth estimation pipelines
6
  pipe_base = pipeline(task="depth-estimation", model="LiheYoung/depth-anything-base-hf")
 
15
  depth_intel = pipe_intel(image)["depth"]
16
  depth_beit = pipe_beit(image)["depth"]
17
 
 
 
 
 
 
 
18
  return depth_base, depth_small, depth_intel, depth_beit
19
 
 
 
 
 
 
20
  # Create a Gradio interface using Blocks
21
  with gr.Blocks() as iface:
22
  gr.Markdown("# Multi-Model Depth Estimation\nUpload an image to get depth estimation maps from multiple models.")
 
26
 
27
  with gr.Row():
28
  with gr.Column():
29
+ output_base = gr.Image(type="pil", label="LiheYoung/depth-anything-base-hf", interactive=False)
30
+ output_small = gr.Image(type="pil", label="LiheYoung/depth-anything-small-hf", interactive=False)
31
  with gr.Column():
32
+ output_intel = gr.Image(type="pil", label="Intel/dpt-swinv2-tiny-256", interactive=False)
33
+ output_beit = gr.Image(type="pil", label="Intel/dpt-beit-base-384", interactive=False)
34
 
35
  input_image.change(fn=estimate_depths, inputs=input_image, outputs=[output_base, output_small, output_intel, output_beit])
36