Tohru127 commited on
Commit
f8d6272
·
verified ·
1 Parent(s): b3bfd8a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -56
app.py CHANGED
@@ -1,60 +1,37 @@
1
- import os
2
-
3
- # For preview, prefer GLB (compact)
4
- return str(glb_path), [str(glb_path), str(obj_path), str(fused)], "\n".join(logs[-6:]), gr.update(visible=True)
5
-
6
- except Exception as e:
7
- logs.append(f"\n[ERROR]\n{e}")
8
- return None, None, "\n".join(logs), gr.update(visible=False)
9
-
 
 
10
 
11
  def ui():
12
- with gr.Blocks(title="Sparse MultiView 3D (Urban Planning)", theme=gr.themes.Soft()) as demo:
13
- gr.Markdown(
14
- """
15
- # 🏙️ Sparse Multi‑View 3D for Urban Planning
16
- Upload **3–30 photos** of a scene (streetscape, plaza, façade). We estimate camera poses with **COLMAP**, build a **dense point cloud**, and **mesh** it with Open3D.
17
- **Tips for sparse captures:** overlap ~60–70%, varying viewpoints (walk an arc), avoid moving cars/people when possible.
18
- """
19
- )
20
- with gr.Row():
21
- with gr.Column(scale=2):
22
- imgs = gr.UploadButton("Upload images (JPG/PNG)", file_types=["image"], file_count="multiple")
23
- gallery = gr.Gallery(label="Selected", columns=6, height=160)
24
- imgs.upload(lambda files: [(f.name, Image.open(f).convert('RGB')) for f in files], imgs, gallery)
25
-
26
- with gr.Accordion("Reconstruction settings", open=False):
27
- max_px = gr.Slider(1024, 4096, value=2400, step=64, label="Max image size (px, longest side)")
28
- match_mode = gr.Radio(["exhaustive", "sequential", "spatial"], value="sequential", label="Matching mode")
29
- use_gpu_sift = gr.Checkbox(True, label="Use GPU for SIFT (if available)")
30
- with gr.Accordion("Meshing", open=True):
31
- voxel = gr.Slider(0.0, 0.05, value=0.01, step=0.005, label="Voxel downsample (m, approx units)")
32
- depth = gr.Slider(6, 12, value=9, step=1, label="Poisson depth (higher → more detail)")
33
- tris = gr.Slider(0, 500_000, value=150_000, step=10_000, label="Target triangles (0 = keep)")
34
-
35
- run = gr.Button("▶ Reconstruct 3D")
36
- with gr.Column(scale=1):
37
- preview = gr.Model3D(label="Mesh preview", visible=False)
38
- files_out = gr.Files(label="Downloads (GLB/OBJ/PLY)")
39
- logs = gr.Markdown("Logs will appear here after running…")
40
-
41
- run.click(
42
- run_pipeline,
43
- [gallery, max_px, match_mode, use_gpu_sift, voxel, depth, tris],
44
- [preview, files_out, logs, preview],
45
- queue=True,
46
- )
47
-
48
- gr.Markdown(
49
- """
50
- ### Notes & Scaling
51
- - Results are in **arbitrary units** (SfM scale). For metric scale, align the mesh in GIS/CAD using known distances.
52
- - Outdoor scenes with repetitive textures (glass, trees) can be challenging—add a few more oblique views if possible.
53
- """
54
- )
55
-
56
- return demo
57
-
58
 
59
  if __name__ == "__main__":
60
- ui().launch()
 
1
+ import gradio as gr
2
+ from PIL import Image
3
+
4
+ def run_pipeline(gallery, max_px, match_mode, use_gpu_sift, voxel, depth, tris):
5
+ try:
6
+ logs = []
7
+ # TODO: your pipeline here
8
+ # return (preview_path, [file_paths...], "\n".join(logs[-6:]), gr.update(visible=True))
9
+ return None, [], "Ready.", gr.update(visible=False)
10
+ except Exception as e:
11
+ return None, None, f"[ERROR]\n{e}", gr.update(visible=False)
12
 
13
  def ui():
14
+ with gr.Blocks(title="Sparse Multi-View 3D (Urban Planning)") as demo:
15
+ gr.Markdown("# Sparse Multi-View 3D for Urban Planning")
16
+ with gr.Row():
17
+ with gr.Column(scale=2):
18
+ imgs = gr.UploadButton("Upload images (JPG/PNG)", file_types=["image"], file_count="multiple")
19
+ gallery = gr.Gallery(label="Selected", columns=6, height=160)
20
+ imgs.upload(lambda files: [(f.name, Image.open(f).convert('RGB')) for f in files], imgs, gallery)
21
+ max_px = gr.Slider(1024, 4096, value=2400, step=64, label="Max image size (px)")
22
+ match_mode = gr.Radio(["exhaustive", "sequential", "spatial"], value="sequential", label="Matching mode")
23
+ use_gpu_sift = gr.Checkbox(True, label="Use GPU for SIFT (if available)")
24
+ voxel = gr.Slider(0.0, 0.05, value=0.01, step=0.005, label="Voxel downsample")
25
+ depth = gr.Slider(6, 12, value=9, step=1, label="Poisson depth")
26
+ tris = gr.Slider(0, 500_000, value=150_000, step=10_000, label="Target triangles")
27
+ run = gr.Button("▶ Reconstruct 3D")
28
+ with gr.Column(scale=1):
29
+ preview = gr.Model3D(label="Mesh preview", visible=False)
30
+ files_out = gr.Files(label="Downloads (GLB/OBJ/PLY)")
31
+ logs = gr.Markdown("Logs will appear here after running…")
32
+ run.click(run_pipeline, [gallery, max_px, match_mode, use_gpu_sift, voxel, depth, tris],
33
+ [preview, files_out, logs, preview], queue=True)
34
+ return demo
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
  if __name__ == "__main__":
37
+ ui().launch()