prithivMLmods commited on
Commit
6f99b72
Β·
verified Β·
1 Parent(s): 64e6415

update app

Browse files
Files changed (1) hide show
  1. app.py +1 -51
app.py CHANGED
@@ -136,10 +136,6 @@ model = None
136
  TMP_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tmp')
137
  os.makedirs(TMP_DIR, exist_ok=True)
138
 
139
-
140
- # -------------------------------------------------------------------------
141
- # Rerun visualization helper
142
- # -------------------------------------------------------------------------
143
  def predictions_to_rrd(predictions, glbfile, target_dir, frame_filter="All", show_cam=True):
144
  run_id = str(uuid.uuid4())
145
  timestamp = datetime.now().strftime("%Y-%m-%dT%H%M%S")
@@ -239,9 +235,6 @@ def predictions_to_rrd(predictions, glbfile, target_dir, frame_filter="All", sho
239
  return rrd_path
240
 
241
 
242
- # -------------------------------------------------------------------------
243
- # 1) Core model inference
244
- # -------------------------------------------------------------------------
245
  @spaces.GPU(duration=120)
246
  def run_model(target_dir, apply_mask=True, mask_edges=True, filter_black_bg=False, filter_white_bg=False):
247
  global model
@@ -387,10 +380,6 @@ def populate_visualization_tabs(processed_data):
387
  return None, None, None, []
388
  return update_depth_view(processed_data, 0), update_normal_view(processed_data, 0), update_measure_view(processed_data, 0)[0], []
389
 
390
-
391
- # -------------------------------------------------------------------------
392
- # 2) Handle uploaded video/images
393
- # -------------------------------------------------------------------------
394
  def handle_uploads(unified_upload, s_time_interval=1.0):
395
  start_time = time.time()
396
  gc.collect()
@@ -453,9 +442,6 @@ def handle_uploads(unified_upload, s_time_interval=1.0):
453
  return target_dir, image_paths
454
 
455
 
456
- # -------------------------------------------------------------------------
457
- # 3) Reconstruction
458
- # -------------------------------------------------------------------------
459
  @spaces.GPU(duration=120)
460
  def gradio_demo(target_dir, frame_filter="All", show_cam=True, filter_black_bg=False, filter_white_bg=False, apply_mask=True, show_mesh=True):
461
  if not os.path.isdir(target_dir) or target_dir == "None":
@@ -506,9 +492,6 @@ def gradio_demo(target_dir, frame_filter="All", show_cam=True, filter_black_bg=F
506
  )
507
 
508
 
509
- # -------------------------------------------------------------------------
510
- # 4) Helper / visualization functions
511
- # -------------------------------------------------------------------------
512
  def colorize_depth(depth_map, mask=None):
513
  if depth_map is None:
514
  return None
@@ -672,9 +655,6 @@ def update_all_views_on_filter_change(target_dir, filter_black_bg, filter_white_
672
  return processed_data, None, None, None, []
673
 
674
 
675
- # -------------------------------------------------------------------------
676
- # Example scene functions
677
- # -------------------------------------------------------------------------
678
  def get_scene_info(examples_dir):
679
  import glob
680
  scenes = []
@@ -702,9 +682,6 @@ def load_example_scene(scene_name, examples_dir="examples"):
702
  return None, target_dir, image_paths, f"Loaded '{scene_name}' β€” {selected_scene['num_images']} images. Click Reconstruct."
703
 
704
 
705
- # -------------------------------------------------------------------------
706
- # CSS
707
- # -------------------------------------------------------------------------
708
  CUSTOM_CSS = (GRADIO_CSS or "") + """
709
  /* ── Page shell ── */
710
  #app-shell {
@@ -831,28 +808,21 @@ CUSTOM_CSS = (GRADIO_CSS or "") + """
831
 
832
  """
833
 
834
- # -------------------------------------------------------------------------
835
- # 6) Build Gradio UI
836
- # -------------------------------------------------------------------------
837
  with gr.Blocks() as demo:
838
 
839
- # Hidden state
840
  is_example = gr.Textbox(visible=False, value="None")
841
  num_images = gr.Textbox(visible=False, value="None")
842
  processed_data_state = gr.State(value=None)
843
  measure_points_state = gr.State(value=[])
844
  target_dir_output = gr.Textbox(visible=False, value="None")
845
 
846
- # ── Header ──────────────────────────────────────────────────────────
847
  with gr.Column(elem_id="app-shell"):
848
  with gr.Column(elem_id="app-header"):
849
  gr.Markdown("# **Map-Anything-v1**", elem_id="main-title")
850
  gr.Markdown("Metric 3D Reconstruction (Point Cloud and Camera Poses)")
851
 
852
- # ── Main two-column layout ───────────────────────────────────────
853
  with gr.Row(equal_height=False):
854
 
855
- # ── LEFT PANEL ─────────────────────────────────────────────
856
  with gr.Column(elem_id="left-panel", scale=0):
857
 
858
  unified_upload = gr.File(
@@ -890,7 +860,6 @@ with gr.Blocks() as demo:
890
 
891
  submit_btn = gr.Button("Reconstruct", variant="primary", elem_id="btn-reconstruct")
892
 
893
- # Options accordion
894
  with gr.Accordion("Options", open=False, elem_id="options-panel"):
895
  gr.Markdown("### Point Cloud")
896
  show_cam = gr.Checkbox(label="Show cameras", value=True)
@@ -906,26 +875,21 @@ with gr.Blocks() as demo:
906
  elem_id="frame-filter", show_label=True,
907
  )
908
 
909
- # ── RIGHT PANEL ────────────────────────────────────────────
910
  with gr.Column(elem_id="right-panel", scale=1):
911
 
912
- # Status log
913
  log_output = gr.Markdown(
914
  "Upload a video or images, then click **Reconstruct**.",
915
  elem_id="log-strip",
916
  )
917
 
918
- # Viewer tabs
919
  with gr.Tabs(elem_id="viewer-tabs"):
920
 
921
- # 3-D View
922
  with gr.Tab("3D View"):
923
  reconstruction_output = Rerun(
924
  label="Rerun 3D Viewer",
925
- height=630,
926
  )
927
 
928
- # Depth
929
  with gr.Tab("Depth"):
930
  with gr.Row(elem_classes=["nav-row"]):
931
  prev_depth_btn = gr.Button("β—€ Prev", size="sm", scale=1)
@@ -940,7 +904,6 @@ with gr.Blocks() as demo:
940
  format="png", interactive=False,
941
  )
942
 
943
- # Normal
944
  with gr.Tab("Normal"):
945
  with gr.Row(elem_classes=["nav-row"]):
946
  prev_normal_btn = gr.Button("β—€ Prev", size="sm", scale=1)
@@ -955,7 +918,6 @@ with gr.Blocks() as demo:
955
  format="png", interactive=False,
956
  )
957
 
958
- # Measure
959
  with gr.Tab("Measure"):
960
  gr.Markdown(MEASURE_INSTRUCTIONS_HTML)
961
  with gr.Row(elem_classes=["nav-row"]):
@@ -976,7 +938,6 @@ with gr.Blocks() as demo:
976
  )
977
  measure_text = gr.Markdown("")
978
 
979
- # ── Examples ────────────────────────────────────────────────────
980
  with gr.Column(elem_id="examples-section"):
981
  gr.Markdown("## Example Scenes")
982
  gr.Markdown("Click a thumbnail to load the scene, then press **Reconstruct**.")
@@ -1009,11 +970,6 @@ with gr.Blocks() as demo:
1009
  with gr.Column(scale=1, min_width=140):
1010
  pass
1011
 
1012
- # =========================================================================
1013
- # Event wiring
1014
- # =========================================================================
1015
-
1016
- # Reconstruct button
1017
  submit_btn.click(
1018
  fn=clear_fields, inputs=[], outputs=[reconstruction_output]
1019
  ).then(
@@ -1028,7 +984,6 @@ with gr.Blocks() as demo:
1028
  ],
1029
  ).then(fn=lambda: "False", inputs=[], outputs=[is_example])
1030
 
1031
- # Live visualization option updates
1032
  for trigger_inputs, trigger in [
1033
  ([target_dir_output, frame_filter, show_cam, is_example, filter_black_bg, filter_white_bg, show_mesh], frame_filter.change),
1034
  ([target_dir_output, frame_filter, show_cam, is_example], show_cam.change),
@@ -1055,7 +1010,6 @@ with gr.Blocks() as demo:
1055
  [processed_data_state, depth_map, normal_map, measure_image, measure_points_state],
1056
  )
1057
 
1058
- # Upload handling
1059
  def update_gallery_on_unified_upload(files, interval):
1060
  if not files:
1061
  return None, None, None
@@ -1093,14 +1047,12 @@ with gr.Blocks() as demo:
1093
  outputs=[target_dir_output, image_gallery, log_output, resample_btn],
1094
  )
1095
 
1096
- # Measure tab
1097
  measure_image.select(
1098
  fn=measure,
1099
  inputs=[processed_data_state, measure_points_state, measure_view_selector],
1100
  outputs=[measure_image, measure_points_state, measure_text],
1101
  )
1102
 
1103
- # Depth tab navigation
1104
  prev_depth_btn.click(
1105
  fn=lambda pd, sel: navigate_depth_view(pd, sel, -1),
1106
  inputs=[processed_data_state, depth_view_selector], outputs=[depth_view_selector, depth_map],
@@ -1114,7 +1066,6 @@ with gr.Blocks() as demo:
1114
  inputs=[processed_data_state, depth_view_selector], outputs=[depth_map],
1115
  )
1116
 
1117
- # Normal tab navigation
1118
  prev_normal_btn.click(
1119
  fn=lambda pd, sel: navigate_normal_view(pd, sel, -1),
1120
  inputs=[processed_data_state, normal_view_selector], outputs=[normal_view_selector, normal_map],
@@ -1128,7 +1079,6 @@ with gr.Blocks() as demo:
1128
  inputs=[processed_data_state, normal_view_selector], outputs=[normal_map],
1129
  )
1130
 
1131
- # Measure tab navigation
1132
  prev_measure_btn.click(
1133
  fn=lambda pd, sel: navigate_measure_view(pd, sel, -1),
1134
  inputs=[processed_data_state, measure_view_selector],
 
136
  TMP_DIR = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'tmp')
137
  os.makedirs(TMP_DIR, exist_ok=True)
138
 
 
 
 
 
139
  def predictions_to_rrd(predictions, glbfile, target_dir, frame_filter="All", show_cam=True):
140
  run_id = str(uuid.uuid4())
141
  timestamp = datetime.now().strftime("%Y-%m-%dT%H%M%S")
 
235
  return rrd_path
236
 
237
 
 
 
 
238
  @spaces.GPU(duration=120)
239
  def run_model(target_dir, apply_mask=True, mask_edges=True, filter_black_bg=False, filter_white_bg=False):
240
  global model
 
380
  return None, None, None, []
381
  return update_depth_view(processed_data, 0), update_normal_view(processed_data, 0), update_measure_view(processed_data, 0)[0], []
382
 
 
 
 
 
383
  def handle_uploads(unified_upload, s_time_interval=1.0):
384
  start_time = time.time()
385
  gc.collect()
 
442
  return target_dir, image_paths
443
 
444
 
 
 
 
445
  @spaces.GPU(duration=120)
446
  def gradio_demo(target_dir, frame_filter="All", show_cam=True, filter_black_bg=False, filter_white_bg=False, apply_mask=True, show_mesh=True):
447
  if not os.path.isdir(target_dir) or target_dir == "None":
 
492
  )
493
 
494
 
 
 
 
495
  def colorize_depth(depth_map, mask=None):
496
  if depth_map is None:
497
  return None
 
655
  return processed_data, None, None, None, []
656
 
657
 
 
 
 
658
  def get_scene_info(examples_dir):
659
  import glob
660
  scenes = []
 
682
  return None, target_dir, image_paths, f"Loaded '{scene_name}' β€” {selected_scene['num_images']} images. Click Reconstruct."
683
 
684
 
 
 
 
685
  CUSTOM_CSS = (GRADIO_CSS or "") + """
686
  /* ── Page shell ── */
687
  #app-shell {
 
808
 
809
  """
810
 
 
 
 
811
  with gr.Blocks() as demo:
812
 
 
813
  is_example = gr.Textbox(visible=False, value="None")
814
  num_images = gr.Textbox(visible=False, value="None")
815
  processed_data_state = gr.State(value=None)
816
  measure_points_state = gr.State(value=[])
817
  target_dir_output = gr.Textbox(visible=False, value="None")
818
 
 
819
  with gr.Column(elem_id="app-shell"):
820
  with gr.Column(elem_id="app-header"):
821
  gr.Markdown("# **Map-Anything-v1**", elem_id="main-title")
822
  gr.Markdown("Metric 3D Reconstruction (Point Cloud and Camera Poses)")
823
 
 
824
  with gr.Row(equal_height=False):
825
 
 
826
  with gr.Column(elem_id="left-panel", scale=0):
827
 
828
  unified_upload = gr.File(
 
860
 
861
  submit_btn = gr.Button("Reconstruct", variant="primary", elem_id="btn-reconstruct")
862
 
 
863
  with gr.Accordion("Options", open=False, elem_id="options-panel"):
864
  gr.Markdown("### Point Cloud")
865
  show_cam = gr.Checkbox(label="Show cameras", value=True)
 
875
  elem_id="frame-filter", show_label=True,
876
  )
877
 
 
878
  with gr.Column(elem_id="right-panel", scale=1):
879
 
 
880
  log_output = gr.Markdown(
881
  "Upload a video or images, then click **Reconstruct**.",
882
  elem_id="log-strip",
883
  )
884
 
 
885
  with gr.Tabs(elem_id="viewer-tabs"):
886
 
 
887
  with gr.Tab("3D View"):
888
  reconstruction_output = Rerun(
889
  label="Rerun 3D Viewer",
890
+ height=680,
891
  )
892
 
 
893
  with gr.Tab("Depth"):
894
  with gr.Row(elem_classes=["nav-row"]):
895
  prev_depth_btn = gr.Button("β—€ Prev", size="sm", scale=1)
 
904
  format="png", interactive=False,
905
  )
906
 
 
907
  with gr.Tab("Normal"):
908
  with gr.Row(elem_classes=["nav-row"]):
909
  prev_normal_btn = gr.Button("β—€ Prev", size="sm", scale=1)
 
918
  format="png", interactive=False,
919
  )
920
 
 
921
  with gr.Tab("Measure"):
922
  gr.Markdown(MEASURE_INSTRUCTIONS_HTML)
923
  with gr.Row(elem_classes=["nav-row"]):
 
938
  )
939
  measure_text = gr.Markdown("")
940
 
 
941
  with gr.Column(elem_id="examples-section"):
942
  gr.Markdown("## Example Scenes")
943
  gr.Markdown("Click a thumbnail to load the scene, then press **Reconstruct**.")
 
970
  with gr.Column(scale=1, min_width=140):
971
  pass
972
 
 
 
 
 
 
973
  submit_btn.click(
974
  fn=clear_fields, inputs=[], outputs=[reconstruction_output]
975
  ).then(
 
984
  ],
985
  ).then(fn=lambda: "False", inputs=[], outputs=[is_example])
986
 
 
987
  for trigger_inputs, trigger in [
988
  ([target_dir_output, frame_filter, show_cam, is_example, filter_black_bg, filter_white_bg, show_mesh], frame_filter.change),
989
  ([target_dir_output, frame_filter, show_cam, is_example], show_cam.change),
 
1010
  [processed_data_state, depth_map, normal_map, measure_image, measure_points_state],
1011
  )
1012
 
 
1013
  def update_gallery_on_unified_upload(files, interval):
1014
  if not files:
1015
  return None, None, None
 
1047
  outputs=[target_dir_output, image_gallery, log_output, resample_btn],
1048
  )
1049
 
 
1050
  measure_image.select(
1051
  fn=measure,
1052
  inputs=[processed_data_state, measure_points_state, measure_view_selector],
1053
  outputs=[measure_image, measure_points_state, measure_text],
1054
  )
1055
 
 
1056
  prev_depth_btn.click(
1057
  fn=lambda pd, sel: navigate_depth_view(pd, sel, -1),
1058
  inputs=[processed_data_state, depth_view_selector], outputs=[depth_view_selector, depth_map],
 
1066
  inputs=[processed_data_state, depth_view_selector], outputs=[depth_map],
1067
  )
1068
 
 
1069
  prev_normal_btn.click(
1070
  fn=lambda pd, sel: navigate_normal_view(pd, sel, -1),
1071
  inputs=[processed_data_state, normal_view_selector], outputs=[normal_view_selector, normal_map],
 
1079
  inputs=[processed_data_state, normal_view_selector], outputs=[normal_map],
1080
  )
1081
 
 
1082
  prev_measure_btn.click(
1083
  fn=lambda pd, sel: navigate_measure_view(pd, sel, -1),
1084
  inputs=[processed_data_state, measure_view_selector],