Akash Raj commited on
Commit
c1a53ad
1 Parent(s): 1f8126a
Files changed (1) hide show
  1. app.py +24 -30
app.py CHANGED
@@ -9,43 +9,37 @@ pipe_small = pipeline(task="depth-estimation", model="LiheYoung/depth-anything-s
9
  pipe_intel = pipeline(task="depth-estimation", model="Intel/dpt-swinv2-tiny-256")
10
  pipe_beit = pipeline(task="depth-estimation", model="Intel/dpt-beit-base-384")
11
 
12
- def estimate_depths(image):
13
- # Perform depth estimation with each pipeline
14
- depth_base = pipe_base(image)["depth"]
15
- depth_small = pipe_small(image)["depth"]
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
33
- iface = gr.Interface(
34
- fn=estimate_depths,
35
- inputs=gr.Image(type="pil"),
36
- outputs=[
37
- gr.Image(type="numpy", label="LiheYoung/depth-anything-base-hf"),
38
- gr.Image(type="numpy", label="LiheYoung/depth-anything-small-hf"),
39
- gr.Image(type="numpy", label="Intel/dpt-swinv2-tiny-256"),
40
- gr.Image(type="numpy", label="Intel/dpt-beit-base-384")
41
- ],
42
- title="Multi-Model Depth Estimation",
43
- description="Upload an image to get depth estimation maps from multiple models.",
44
- layout="horizontal"
45
- )
 
 
 
46
 
47
- # Launch the Gradio app
48
- iface.launch()
49
 
50
 
51
  """
 
9
  pipe_intel = pipeline(task="depth-estimation", model="Intel/dpt-swinv2-tiny-256")
10
  pipe_beit = pipeline(task="depth-estimation", model="Intel/dpt-beit-base-384")
11
 
12
+ def process_and_display(pipe, output_component):
13
+ def process_image(image):
14
+ depth_map = pipe(image)["depth"]
15
+ normalized_depth = normalize_depth(depth_map)
16
+ output_component.value = normalized_depth
17
+
18
+ return process_image
 
 
 
 
 
 
 
19
 
20
  def normalize_depth(depth_map):
21
  # Normalize depth map values to range [0, 255] for visualization
22
  normalized_depth = ((depth_map - depth_map.min()) / (depth_map.max() - depth_map.min())) * 255
23
  return normalized_depth.astype(np.uint8)
24
 
25
+ # Create Gradio output components for each pipeline
26
+ output_base = gr.outputs.Image(type="numpy", label="LiheYoung/depth-anything-base-hf")
27
+ output_small = gr.outputs.Image(type="numpy", label="LiheYoung/depth-anything-small-hf")
28
+ output_intel = gr.outputs.Image(type="numpy", label="Intel/dpt-swinv2-tiny-256")
29
+ output_beit = gr.outputs.Image(type="numpy", label="Intel/dpt-beit-base-384")
30
+
31
+ # Create Gradio interfaces for each pipeline
32
+ iface_base = gr.Interface(process_and_display(pipe_base, output_base), inputs=gr.inputs.Image(type="pil"), outputs=output_base, title="Depth Estimation - LiheYoung/depth-anything-base-hf")
33
+ iface_small = gr.Interface(process_and_display(pipe_small, output_small), inputs=gr.inputs.Image(type="pil"), outputs=output_small, title="Depth Estimation - LiheYoung/depth-anything-small-hf")
34
+ iface_intel = gr.Interface(process_and_display(pipe_intel, output_intel), inputs=gr.inputs.Image(type="pil"), outputs=output_intel, title="Depth Estimation - Intel/dpt-swinv2-tiny-256")
35
+ iface_beit = gr.Interface(process_and_display(pipe_beit, output_beit), inputs=gr.inputs.Image(type="pil"), outputs=output_beit, title="Depth Estimation - Intel/dpt-beit-base-384")
36
+
37
+ # Launch the Gradio interfaces
38
+ iface_base.launch()
39
+ iface_small.launch()
40
+ iface_intel.launch()
41
+ iface_beit.launch()
42
 
 
 
43
 
44
 
45
  """