File size: 1,856 Bytes
6f72020
 
7e9d2f3
 
516f50c
 
 
8d63354
1f8126a
516f50c
284f074
 
 
 
8d63354
284f074
 
8d63354
1f8126a
22aa42f
 
 
 
 
72e1e0f
22aa42f
 
 
72e1e0f
 
22aa42f
8d63354
72e1e0f
22aa42f
8d63354
1d0844e
284f074
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from transformers import pipeline
from PIL import Image
import gradio as gr

# Load the Hugging Face depth estimation pipelines
pipe_base = pipeline(task="depth-estimation", model="LiheYoung/depth-anything-base-hf")
pipe_small = pipeline(task="depth-estimation", model="LiheYoung/depth-anything-small-hf")
pipe_large = pipeline(task="depth-estimation", model="LiheYoung/depth-anything-large-hf")
pipe_beit = pipeline(task="depth-estimation", model="Intel/dpt-beit-base-384")

def estimate_depths(image):
    # Perform depth estimation with each pipeline
    depth_base = pipe_base(image)["depth"]
    depth_small = pipe_small(image)["depth"]
    depth_large = pipe_large(image)["depth"]
    depth_beit = pipe_beit(image)["depth"]
    
    return depth_base, depth_small, depth_large, depth_beit

# Create a Gradio interface using Blocks
with gr.Blocks() as iface:
    gr.Markdown("# Multi-Model Depth Estimation\nUpload an image to get depth estimation maps from multiple models.")
    
    with gr.Row():
        input_image = gr.Image(type="pil", label="Input Image", height=400, width=400)
    
    with gr.Row():
        with gr.Column():
            output_base = gr.Image(type="pil", label="LiheYoung/depth-anything-base-hf", interactive=False, height=400, width=400)
            output_small = gr.Image(type="pil", label="LiheYoung/depth-anything-small-hf", interactive=False, height=400, width=400)
        with gr.Column():
            output_large = gr.Image(type="pil", label="LiheYoung/depth-anything-large-hf", interactive=False, height=400, width=400)
            output_beit = gr.Image(type="pil", label="Intel/dpt-beit-base-384", interactive=False, height=400, width=400)

    input_image.change(fn=estimate_depths, inputs=input_image, outputs=[output_base, output_small, output_large, output_beit])

# Launch the Gradio app
iface.launch()