Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -47,6 +47,7 @@ state_dict = torch.load(filepath, map_location="cpu")
|
|
47 |
model.load_state_dict(state_dict)
|
48 |
model = model.to(DEVICE).eval()
|
49 |
|
|
|
50 |
def findNormals(gray_depth, format):
|
51 |
|
52 |
d_im = cv2.cvtColor(cv2.imread(gray_depth).astype(np.uint8), cv2.COLOR_BGR2GRAY)
|
@@ -72,6 +73,26 @@ def findNormals(gray_depth, format):
|
|
72 |
|
73 |
return (normal[:, :, ::-1]).astype(np.uint8)
|
74 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
title = "# Depth Anything V2"
|
76 |
description = """Unofficial demo for **Depth Anything V2**.
|
77 |
Please refer to their [paper](https://arxiv.org/abs/2406.09414), [project page](https://depth-anything-v2.github.io), and [github](https://github.com/DepthAnything/Depth-Anything-V2) for more details."""
|
@@ -80,7 +101,7 @@ Please refer to their [paper](https://arxiv.org/abs/2406.09414), [project page](
|
|
80 |
def predict_depth(image):
|
81 |
return model.infer_image(image)
|
82 |
|
83 |
-
with gr.Blocks(css=css) as demo:
|
84 |
gr.Markdown(title)
|
85 |
gr.Markdown(description)
|
86 |
gr.Markdown("### Depth Prediction demo")
|
@@ -117,6 +138,23 @@ with gr.Blocks(css=css) as demo:
|
|
117 |
colored_depth = (cmap(depth)[:, :, :3] * 255).astype(np.uint8)
|
118 |
|
119 |
gray_depth = Image.fromarray(depth)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
120 |
tmp_gray_depth = tempfile.NamedTemporaryFile(suffix='.png', delete=False)
|
121 |
gray_depth.save(tmp_gray_depth.name)
|
122 |
|
|
|
47 |
model.load_state_dict(state_dict)
|
48 |
model = model.to(DEVICE).eval()
|
49 |
|
50 |
+
|
51 |
def findNormals(gray_depth, format):
|
52 |
|
53 |
d_im = cv2.cvtColor(cv2.imread(gray_depth).astype(np.uint8), cv2.COLOR_BGR2GRAY)
|
|
|
73 |
|
74 |
return (normal[:, :, ::-1]).astype(np.uint8)
|
75 |
|
76 |
+
|
77 |
+
load_svg="""
|
78 |
+
async(img, dpt)=>{
|
79 |
+
document.getElementById('inimage').outerHTML = '<image id="inimage" crossorigin="anonymous" href="' + img + '" x="0" y="0" height="100%" width="100%" style="filter: url(#displacementFilter)"/>';
|
80 |
+
document.getElementById('feimage').outerHTML = '<feImage id="feimage" crossorigin="anonymous" width="100%" height="100%" x="0" y="0" result="10_MAP" href="' + dpt + '"/>';
|
81 |
+
}
|
82 |
+
"""
|
83 |
+
|
84 |
+
|
85 |
+
js="""
|
86 |
+
async()=>{
|
87 |
+
document.getElementById('scale').getElementsByTagName('input')[0].addEventListener('input', displace);
|
88 |
+
|
89 |
+
function displace(e) {
|
90 |
+
document.getElementById('dmap').setAttributeNS(null, 'scale', ''+e.target.value);
|
91 |
+
}
|
92 |
+
}
|
93 |
+
"""
|
94 |
+
|
95 |
+
|
96 |
title = "# Depth Anything V2"
|
97 |
description = """Unofficial demo for **Depth Anything V2**.
|
98 |
Please refer to their [paper](https://arxiv.org/abs/2406.09414), [project page](https://depth-anything-v2.github.io), and [github](https://github.com/DepthAnything/Depth-Anything-V2) for more details."""
|
|
|
101 |
def predict_depth(image):
|
102 |
return model.infer_image(image)
|
103 |
|
104 |
+
with gr.Blocks(js=js, css=css) as demo:
|
105 |
gr.Markdown(title)
|
106 |
gr.Markdown(description)
|
107 |
gr.Markdown("### Depth Prediction demo")
|
|
|
138 |
colored_depth = (cmap(depth)[:, :, :3] * 255).astype(np.uint8)
|
139 |
|
140 |
gray_depth = Image.fromarray(depth)
|
141 |
+
svg = gr.HTML("""
|
142 |
+
<svg id='svg'
|
143 |
+
width='1024'
|
144 |
+
height='512'
|
145 |
+
viewBox='0 0 1024 512'
|
146 |
+
xmlns='http://www.w3.org/2000/svg'>
|
147 |
+
<style></style>
|
148 |
+
<filter id='displacementFilter' color-interpolation-filters='sRGB'>
|
149 |
+
<feImage id='feimage' crossorigin='anonymous' width='100%' height='100%' x='0' y='0' result='10_MAP' href='https://freeali.se/panoramera/examples/basic/f0_dmap_.png'/>
|
150 |
+
<feGaussianBlur result='blurred' in='10_MAP' stdDeviation='15,15' />
|
151 |
+
<feDisplacementMap id='dmap' result='fedm' in2='blurred' in='SourceGraphic' scale='2' xChannelSelector='G' yChannelSelector='A' />
|
152 |
+
</filter>
|
153 |
+
<image id='inimage' crossorigin='anonymous' href='https://freeali.se/panoramera/examples/basic/f0.jpg' x='0' y='0' height='100%' width='100%' style='filter: url(#displacementFilter)'/>
|
154 |
+
</svg>
|
155 |
+
""")
|
156 |
+
scale = gr.Slider(label='Scale', minimum="-128" maximum="128" value="0" step="1" elem_id="scale")
|
157 |
+
gray_depth.change(fn=None, inputs=[original_image, gray_depth], outputs=None, js=load_svg)
|
158 |
tmp_gray_depth = tempfile.NamedTemporaryFile(suffix='.png', delete=False)
|
159 |
gray_depth.save(tmp_gray_depth.name)
|
160 |
|