Spaces:
Running
Running
Akash Raj
commited on
Commit
·
1f8126a
1
Parent(s):
bb518d4
test
Browse files
app.py
CHANGED
|
@@ -1,31 +1,47 @@
|
|
| 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")
|
| 7 |
pipe_small = pipeline(task="depth-estimation", model="LiheYoung/depth-anything-small-hf")
|
| 8 |
pipe_intel = pipeline(task="depth-estimation", model="Intel/dpt-swinv2-tiny-256")
|
|
|
|
| 9 |
|
| 10 |
def estimate_depths(image):
|
| 11 |
# Perform depth estimation with each pipeline
|
| 12 |
depth_base = pipe_base(image)["depth"]
|
| 13 |
depth_small = pipe_small(image)["depth"]
|
| 14 |
depth_intel = pipe_intel(image)["depth"]
|
|
|
|
| 15 |
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Create a Gradio interface
|
| 19 |
iface = gr.Interface(
|
| 20 |
fn=estimate_depths,
|
| 21 |
inputs=gr.Image(type="pil"),
|
| 22 |
outputs=[
|
| 23 |
-
gr.Image(type="
|
| 24 |
-
gr.Image(type="
|
| 25 |
-
gr.Image(type="
|
|
|
|
| 26 |
],
|
| 27 |
title="Multi-Model Depth Estimation",
|
| 28 |
-
description="Upload an image to get depth estimation maps from multiple models."
|
|
|
|
| 29 |
)
|
| 30 |
|
| 31 |
# Launch the Gradio app
|
|
|
|
| 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")
|
| 8 |
pipe_small = pipeline(task="depth-estimation", model="LiheYoung/depth-anything-small-hf")
|
| 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
|