yyfz233 commited on
Commit
f74a9a4
·
1 Parent(s): fb6b82b

Update code for .ply file downloading

Browse files
Files changed (1) hide show
  1. app.py +14 -10
app.py CHANGED
@@ -1,8 +1,3 @@
1
- # Copyright (c) Meta Platforms, Inc. and affiliates.
2
- # All rights reserved.
3
- #
4
- # This source code is licensed under the license found in the
5
- # LICENSE file in the root directory of this source tree.
6
 
7
  import os
8
  import cv2
@@ -467,6 +462,10 @@ def gradio_demo(
467
  )
468
  glbscene.export(file_obj=glbfile)
469
 
 
 
 
 
470
  # Cleanup
471
  del predictions
472
  gc.collect()
@@ -476,7 +475,7 @@ def gradio_demo(
476
  print(f"Total time: {end_time - start_time:.2f} seconds (including IO)")
477
  log_msg = f"Reconstruction Success ({len(all_files)} frames). Waiting for visualization."
478
 
479
- return glbfile, log_msg, gr.Dropdown(choices=frame_filter_choices, value=frame_filter, interactive=True)
480
 
481
 
482
  # -------------------------------------------------------------------------
@@ -539,6 +538,8 @@ def update_visualization(
539
  )
540
  glbscene.export(file_obj=glbfile)
541
 
 
 
542
  return glbfile, "Updating Visualization"
543
 
544
 
@@ -791,6 +792,9 @@ if __name__ == '__main__':
791
  gr.Markdown("### 2. View Reconstruction")
792
  log_output = gr.Markdown("Please upload media and click Reconstruct.", elem_classes=["custom-log"])
793
  reconstruction_output = gr.Model3D(height=480, zoom_speed=0.5, pan_speed=0.5, label="3D Output")
 
 
 
794
 
795
  with gr.Row():
796
  submit_btn = gr.Button("Reconstruct", scale=3, variant="primary")
@@ -836,10 +840,10 @@ if __name__ == '__main__':
836
  target_dir, image_paths = handle_uploads(input_video, input_images, interval)
837
  # Always use "All" for frame_filter in examples
838
  frame_filter = "All"
839
- glbfile, log_msg, dropdown = gradio_demo(
840
  target_dir, conf_thres, frame_filter, show_cam
841
  )
842
- return glbfile, log_msg, target_dir, dropdown, image_paths
843
 
844
  gr.Markdown("Click any row to load an example.", elem_classes=["example-log"])
845
 
@@ -852,7 +856,7 @@ if __name__ == '__main__':
852
  conf_thres,
853
  show_cam,
854
  ],
855
- outputs=[reconstruction_output, log_output, target_dir_output, frame_filter, image_gallery],
856
  fn=example_pipeline,
857
  cache_examples=False,
858
  examples_per_page=50,
@@ -876,7 +880,7 @@ if __name__ == '__main__':
876
  frame_filter,
877
  show_cam,
878
  ],
879
- outputs=[reconstruction_output, log_output, frame_filter],
880
  ).then(
881
  fn=lambda: "False", inputs=[], outputs=[is_example] # set is_example to "False"
882
  )
 
 
 
 
 
 
1
 
2
  import os
3
  import cv2
 
462
  )
463
  glbscene.export(file_obj=glbfile)
464
 
465
+ # we save a .ply file too
466
+ plyfile = glbfile.replace('.glb', '.ply')
467
+ glbscene.export(file_obj=plyfile)
468
+
469
  # Cleanup
470
  del predictions
471
  gc.collect()
 
475
  print(f"Total time: {end_time - start_time:.2f} seconds (including IO)")
476
  log_msg = f"Reconstruction Success ({len(all_files)} frames). Waiting for visualization."
477
 
478
+ return glbfile, plyfile, log_msg, gr.Dropdown(choices=frame_filter_choices, value=frame_filter, interactive=True)
479
 
480
 
481
  # -------------------------------------------------------------------------
 
538
  )
539
  glbscene.export(file_obj=glbfile)
540
 
541
+ glbscene.export(file_obj=glbfile.replace('.glb', '.ply'))
542
+
543
  return glbfile, "Updating Visualization"
544
 
545
 
 
792
  gr.Markdown("### 2. View Reconstruction")
793
  log_output = gr.Markdown("Please upload media and click Reconstruct.", elem_classes=["custom-log"])
794
  reconstruction_output = gr.Model3D(height=480, zoom_speed=0.5, pan_speed=0.5, label="3D Output")
795
+
796
+ # optional to download .ply file
797
+ download_ply_output = gr.File(label="Download .ply Result", interactive=False)
798
 
799
  with gr.Row():
800
  submit_btn = gr.Button("Reconstruct", scale=3, variant="primary")
 
840
  target_dir, image_paths = handle_uploads(input_video, input_images, interval)
841
  # Always use "All" for frame_filter in examples
842
  frame_filter = "All"
843
+ glbfile, ply_file, log_msg, dropdown = gradio_demo(
844
  target_dir, conf_thres, frame_filter, show_cam
845
  )
846
+ return glbfile, ply_file, log_msg, target_dir, dropdown, image_paths
847
 
848
  gr.Markdown("Click any row to load an example.", elem_classes=["example-log"])
849
 
 
856
  conf_thres,
857
  show_cam,
858
  ],
859
+ outputs=[reconstruction_output, download_ply_output, log_output, target_dir_output, frame_filter, image_gallery],
860
  fn=example_pipeline,
861
  cache_examples=False,
862
  examples_per_page=50,
 
880
  frame_filter,
881
  show_cam,
882
  ],
883
+ outputs=[reconstruction_output, download_ply_output, log_output, frame_filter],
884
  ).then(
885
  fn=lambda: "False", inputs=[], outputs=[is_example] # set is_example to "False"
886
  )