Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,22 +6,20 @@ from PIL import Image
|
|
| 6 |
import gradio as gr
|
| 7 |
from gradio_client import Client
|
| 8 |
import os
|
| 9 |
-
import json
|
| 10 |
import spaces
|
|
|
|
| 11 |
|
| 12 |
dpt_beit = pipeline(task = "depth-estimation", model="Intel/dpt-beit-base-384")
|
| 13 |
depth_anything = pipeline(task = "depth-estimation", model="nielsr/depth-anything-small")
|
| 14 |
dpt_large = pipeline(task = "depth-estimation", model="intel/dpt-large")
|
| 15 |
-
|
| 16 |
@spaces.GPU
|
| 17 |
def depth_anything_inference(image_path):
|
| 18 |
return depth_anything(image_path)["depth"]
|
| 19 |
-
|
| 20 |
@spaces.GPU
|
| 21 |
def dpt_beit_inference(image):
|
| 22 |
return dpt_beit(image)["depth"]
|
| 23 |
|
| 24 |
-
|
| 25 |
def dpt_large_inference(image):
|
| 26 |
return dpt_large(image)["depth"]
|
| 27 |
|
|
@@ -30,13 +28,33 @@ def infer(image):
|
|
| 30 |
return dpt_large_inference(image), dpt_beit_inference(image), depth_anything_inference(image)
|
| 31 |
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
import gradio as gr
|
| 7 |
from gradio_client import Client
|
| 8 |
import os
|
|
|
|
| 9 |
import spaces
|
| 10 |
+
import json
|
| 11 |
|
| 12 |
dpt_beit = pipeline(task = "depth-estimation", model="Intel/dpt-beit-base-384")
|
| 13 |
depth_anything = pipeline(task = "depth-estimation", model="nielsr/depth-anything-small")
|
| 14 |
dpt_large = pipeline(task = "depth-estimation", model="intel/dpt-large")
|
|
|
|
| 15 |
@spaces.GPU
|
| 16 |
def depth_anything_inference(image_path):
|
| 17 |
return depth_anything(image_path)["depth"]
|
|
|
|
| 18 |
@spaces.GPU
|
| 19 |
def dpt_beit_inference(image):
|
| 20 |
return dpt_beit(image)["depth"]
|
| 21 |
|
| 22 |
+
@spaces.GPU
|
| 23 |
def dpt_large_inference(image):
|
| 24 |
return dpt_large(image)["depth"]
|
| 25 |
|
|
|
|
| 28 |
return dpt_large_inference(image), dpt_beit_inference(image), depth_anything_inference(image)
|
| 29 |
|
| 30 |
|
| 31 |
+
css = """
|
| 32 |
+
#mkd {
|
| 33 |
+
height: 500px;
|
| 34 |
+
overflow: auto;
|
| 35 |
+
border: 1px solid #ccc;
|
| 36 |
+
}
|
| 37 |
+
"""
|
| 38 |
+
with gr.Blocks(css=css) as demo:
|
| 39 |
+
gr.HTML("<h1><center>Compare Depth Estimation Models<center><h1>")
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
with gr.Row():
|
| 43 |
+
input_img = gr.Image(label="Input Image")
|
| 44 |
+
with gr.Row():
|
| 45 |
+
output_1 = gr.Image(type="pil", label="DPT-Large")
|
| 46 |
+
output_2 = gr.Image(type="pil", label="DPT with BeiT Backbone")
|
| 47 |
+
output_3 = gr.Image(type="pil", label="Depth Anything")
|
| 48 |
+
|
| 49 |
+
gr.Examples([["https://huggingface.co/spaces/merve/compare_depth_models/resolve/main/bee.JPG"]],
|
| 50 |
+
inputs = input_img,
|
| 51 |
+
outputs = [output_1, output_2, output_3],
|
| 52 |
+
fn=infer,
|
| 53 |
+
cache_examples=True,
|
| 54 |
+
label='Click on any Examples below to get depth estimation results quickly 👇'
|
| 55 |
+
)
|
| 56 |
+
|
| 57 |
+
input_img.change(infer, [input_img], [output_1, output_2, output_3])
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
gr.launch(debug=True)
|