weijielyu commited on
Commit
5095eb7
·
1 Parent(s): f81f220
Files changed (1) hide show
  1. app.py +22 -34
app.py CHANGED
@@ -59,26 +59,6 @@ def _log_viewer_file(ply_path: Path):
59
  }
60
  print("[VIEWER-RETURN]", json.dumps(info))
61
 
62
- def _write_sample_cube_ply(dst):
63
- """Write a tiny ASCII PLY point-cloud cube; handy to sanity-check the Model3D wiring."""
64
- import random
65
- dst = Path(dst)
66
- dst.parent.mkdir(parents=True, exist_ok=True)
67
- pts = []
68
- for _ in range(2000):
69
- x, y, z = (random.uniform(-0.5, 0.5) for _ in range(3))
70
- r, g, b = (random.randint(80, 255) for _ in range(3))
71
- pts.append((x, y, z, r, g, b))
72
- with open(dst, "w") as f:
73
- f.write("ply\nformat ascii 1.0\n")
74
- f.write(f"element vertex {len(pts)}\n")
75
- f.write("property float x\nproperty float y\nproperty float z\n")
76
- f.write("property uchar red\nproperty uchar green\nproperty uchar blue\n")
77
- f.write("end_header\n")
78
- for x, y, z, r, g, b in pts:
79
- f.write(f"{x} {y} {z} {r} {g} {b}\n")
80
- return str(dst)
81
-
82
  # -----------------------------
83
  # Ensure diff-gaussian-rasterization builds for current GPU
84
  # -----------------------------
@@ -361,11 +341,30 @@ class FaceLiftPipeline:
361
  # Final CUDA cache clear
362
  torch.cuda.empty_cache()
363
 
364
- # Return paths directly (Gradio components handle them automatically)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
365
  return (
366
  str(output_path), # Reconstruction grid
367
  str(turntable_path), # Turntable video
368
- str(ply_path), # Viewer
369
  str(ply_path), # Download file
370
  )
371
 
@@ -413,13 +412,10 @@ def main():
413
  examples_per_page=10,
414
  )
415
 
416
- # Optional: a quick sanity button to verify the viewer path wiring
417
- sample_btn = gr.Button("🔧 Load Sample Cube (sanity test)")
418
-
419
  with gr.Column(scale=1):
420
  out_recon = gr.Image(label="3D Reconstruction Views")
421
  out_video = gr.PlayableVideo(label="Turntable Animation (360° View)", height=600)
422
- out_viewer = gr.Model3D(label="Interactive 3D Viewer (.ply)", height=600)
423
  out_ply = gr.File(label="Download 3D Model (.ply)")
424
 
425
  # Wrapper: call the pipeline and forward outputs in the exact order expected
@@ -433,14 +429,6 @@ def main():
433
  outputs=[out_recon, out_video, out_viewer, out_ply],
434
  )
435
 
436
- # Wire the sample cube sanity test
437
- def _load_sample_viewer():
438
- sample_path = _write_sample_cube_ply(Path("outputs") / "sample_cube.ply")
439
- print("[VIEWER-SAMPLE]", os.path.abspath(sample_path))
440
- return sample_path
441
-
442
- sample_btn.click(_load_sample_viewer, inputs=[], outputs=[out_viewer])
443
-
444
  demo.queue(max_size=10)
445
  demo.launch(share=True, server_name="0.0.0.0", server_port=7860, show_error=True)
446
 
 
59
  }
60
  print("[VIEWER-RETURN]", json.dumps(info))
61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
  # -----------------------------
63
  # Ensure diff-gaussian-rasterization builds for current GPU
64
  # -----------------------------
 
341
  # Final CUDA cache clear
342
  torch.cuda.empty_cache()
343
 
344
+ # Create viewer HTML with iframe pointing to external viewer
345
+ ply_url = f"/file={ply_path}"
346
+ viewer_html = f"""
347
+ <div style="width:100%; height:600px; position:relative; border-radius:8px; overflow:hidden; border:1px solid #333;">
348
+ <iframe
349
+ src="https://www.wlyu.me/FaceLift/splat/index.html?url={ply_url}"
350
+ style="width:100%; height:100%; border:none;"
351
+ allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
352
+ allowfullscreen>
353
+ </iframe>
354
+ </div>
355
+ <div style="text-align:center; margin-top:10px;">
356
+ <a href="https://www.wlyu.me/FaceLift/splat/index.html?url={ply_url}"
357
+ target="_blank"
358
+ style="color:#4CAF50; text-decoration:none; font-size:13px;">
359
+ 🔗 Open viewer in new tab for better performance
360
+ </a>
361
+ </div>
362
+ """
363
+
364
  return (
365
  str(output_path), # Reconstruction grid
366
  str(turntable_path), # Turntable video
367
+ viewer_html, # Viewer HTML
368
  str(ply_path), # Download file
369
  )
370
 
 
412
  examples_per_page=10,
413
  )
414
 
 
 
 
415
  with gr.Column(scale=1):
416
  out_recon = gr.Image(label="3D Reconstruction Views")
417
  out_video = gr.PlayableVideo(label="Turntable Animation (360° View)", height=600)
418
+ out_viewer = gr.HTML(label="🎮 Interactive 3D Viewer")
419
  out_ply = gr.File(label="Download 3D Model (.ply)")
420
 
421
  # Wrapper: call the pipeline and forward outputs in the exact order expected
 
429
  outputs=[out_recon, out_video, out_viewer, out_ply],
430
  )
431
 
 
 
 
 
 
 
 
 
432
  demo.queue(max_size=10)
433
  demo.launch(share=True, server_name="0.0.0.0", server_port=7860, show_error=True)
434