Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -48,7 +48,7 @@ def process_image(image_path):
|
|
| 48 |
except Exception:
|
| 49 |
gltf_path = create_3d_obj(np.array(image), depth_image, image_path, depth=8)
|
| 50 |
|
| 51 |
-
return
|
| 52 |
|
| 53 |
def create_3d_obj(rgb_image, depth_image, image_path, depth=10):
|
| 54 |
depth_o3d = o3d.geometry.Image(depth_image)
|
|
@@ -80,32 +80,32 @@ def create_3d_obj(rgb_image, depth_image, image_path, depth=10):
|
|
| 80 |
|
| 81 |
return gltf_path
|
| 82 |
|
| 83 |
-
title = "Zero-shot Depth Estimation with DPT + 3D
|
| 84 |
-
description = "
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
-
with gr.Blocks() as iface:
|
| 87 |
-
gr.Markdown("# Zero-shot Depth Estimation with DPT + 3D Point Cloud")
|
| 88 |
with gr.Row():
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
| 92 |
|
| 93 |
-
# Embed an iframe for previewing the .gltf
|
| 94 |
with gr.Row():
|
| 95 |
-
gr.
|
|
|
|
|
|
|
|
|
|
| 96 |
|
| 97 |
-
|
| 98 |
-
gltf_path = process_image(image_path)[1]
|
| 99 |
-
iframe_html = f'''
|
| 100 |
-
<script>
|
| 101 |
-
document.getElementById('gltf-viewer').src = 'https://gltf-viewer.donmccurdy.com/?url=file://{gltf_path}';
|
| 102 |
-
</script>
|
| 103 |
-
'''
|
| 104 |
-
return process_image(image_path)[0], gltf_path, iframe_html
|
| 105 |
|
| 106 |
-
|
|
|
|
| 107 |
|
| 108 |
-
iface.launch()
|
| 109 |
|
| 110 |
|
| 111 |
|
|
|
|
| 48 |
except Exception:
|
| 49 |
gltf_path = create_3d_obj(np.array(image), depth_image, image_path, depth=8)
|
| 50 |
|
| 51 |
+
return Image.fromarray(depth_image), gltf_path, gltf_path
|
| 52 |
|
| 53 |
def create_3d_obj(rgb_image, depth_image, image_path, depth=10):
|
| 54 |
depth_o3d = o3d.geometry.Image(depth_image)
|
|
|
|
| 80 |
|
| 81 |
return gltf_path
|
| 82 |
|
| 83 |
+
title = "Zero-shot Depth Estimation with DPT + 3D Model Preview"
|
| 84 |
+
description = "Upload an image to generate a depth map and reconstruct a 3D model in .gltf format."
|
| 85 |
+
|
| 86 |
+
with gr.Blocks() as demo:
|
| 87 |
+
gr.Markdown(f"## {title}")
|
| 88 |
+
gr.Markdown(description)
|
| 89 |
|
|
|
|
|
|
|
| 90 |
with gr.Row():
|
| 91 |
+
with gr.Column():
|
| 92 |
+
image_input = gr.Image(type="filepath", label="Upload Image")
|
| 93 |
+
generate_button = gr.Button("Generate 3D Model")
|
| 94 |
+
|
| 95 |
+
with gr.Column():
|
| 96 |
+
depth_output = gr.Image(label="Predicted Depth", type="pil")
|
| 97 |
|
|
|
|
| 98 |
with gr.Row():
|
| 99 |
+
model_output = gr.Model3D(label="3D Model Preview (GLTF)")
|
| 100 |
+
|
| 101 |
+
with gr.Row():
|
| 102 |
+
file_output = gr.File(label="Download 3D GLTF File")
|
| 103 |
|
| 104 |
+
generate_button.click(fn=process_image, inputs=[image_input], outputs=[depth_output, model_output, file_output])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
|
| 106 |
+
if __name__ == "__main__":
|
| 107 |
+
demo.launch()
|
| 108 |
|
|
|
|
| 109 |
|
| 110 |
|
| 111 |
|