ritianyu commited on
Commit
38e9d5d
·
1 Parent(s): f2e9a22

Fix Gradio Space compatibility

Browse files
Files changed (1) hide show
  1. app.py +34 -6
app.py CHANGED
@@ -1,6 +1,7 @@
1
  from __future__ import annotations
2
 
3
  from functools import lru_cache
 
4
  import os
5
  from pathlib import Path
6
  from typing import Optional
@@ -41,6 +42,20 @@ def _ensure_hf_cache_dirs() -> None:
41
 
42
  _ensure_hf_cache_dirs()
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  import cv2
45
  import gradio as gr
46
  import numpy as np
@@ -122,6 +137,19 @@ DEPTH_VIEW_TAB_ID = "pcd-viewer-tab"
122
  GS_VIEW_TAB_ID = "gs-viewer-tab"
123
  gr.set_static_paths(paths=[str(GS_VIEWER_ROOT)])
124
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
  CSS = """
126
  #top-workspace {
127
  align-items: stretch;
@@ -798,8 +826,8 @@ with gr.Blocks(css=CSS, theme=gr.themes.Soft()) as demo:
798
  with gr.Column(scale=8, min_width=640, elem_id="outputs-column"):
799
  status_output = gr.Markdown()
800
 
801
- with gr.Tabs(selected=DEPTH_VIEW_TAB_ID, elem_id="primary-view-tabs") as primary_view_tabs:
802
- with gr.Tab("PCD Viewer", id=DEPTH_VIEW_TAB_ID, render_children=True):
803
  depth_model_3d = gr.Model3D(
804
  label="Point Cloud Viewer",
805
  display_mode="solid",
@@ -807,11 +835,11 @@ with gr.Blocks(css=CSS, theme=gr.themes.Soft()) as demo:
807
  height=700,
808
  elem_id="depth-model3d-viewer",
809
  )
810
- with gr.Tab("GS Viewer", id=GS_VIEW_TAB_ID, render_children=True):
811
  gs_viewer_html = gr.HTML(elem_id="gs-viewer-html")
812
 
813
- with gr.Tabs(elem_id="secondary-output-tabs"):
814
- with gr.Tab("Depth Analysis", render_children=True):
815
  depth_comparison = gr.Image(
816
  label="RGB vs Depth",
817
  type="filepath",
@@ -831,7 +859,7 @@ with gr.Blocks(css=CSS, theme=gr.themes.Soft()) as demo:
831
  height=260,
832
  elem_id="depth-preview",
833
  )
834
- with gr.Tab("Downloads", render_children=True):
835
  with gr.Row():
836
  depth_download_files = gr.File(label="Depth Files", type="filepath")
837
  gs_download_files = gr.File(label="GS Files", type="filepath")
 
1
  from __future__ import annotations
2
 
3
  from functools import lru_cache
4
+ import inspect
5
  import os
6
  from pathlib import Path
7
  from typing import Optional
 
42
 
43
  _ensure_hf_cache_dirs()
44
 
45
+
46
+ def _ensure_valid_omp_num_threads() -> None:
47
+ value = os.environ.get("OMP_NUM_THREADS", "").strip()
48
+ try:
49
+ if int(value) > 0:
50
+ return
51
+ except (TypeError, ValueError):
52
+ pass
53
+
54
+ os.environ["OMP_NUM_THREADS"] = "1"
55
+
56
+
57
+ _ensure_valid_omp_num_threads()
58
+
59
  import cv2
60
  import gradio as gr
61
  import numpy as np
 
137
  GS_VIEW_TAB_ID = "gs-viewer-tab"
138
  gr.set_static_paths(paths=[str(GS_VIEWER_ROOT)])
139
 
140
+
141
+ def _supports_component_kwarg(component_init, kwarg: str) -> bool:
142
+ try:
143
+ return kwarg in inspect.signature(component_init).parameters
144
+ except (TypeError, ValueError):
145
+ return False
146
+
147
+
148
+ TAB_RENDER_KWARGS = {"render_children": True} if _supports_component_kwarg(gr.Tab.__init__, "render_children") else {}
149
+ TABS_RENDER_KWARGS = (
150
+ {"render_children": True} if _supports_component_kwarg(gr.Tabs.__init__, "render_children") else {}
151
+ )
152
+
153
  CSS = """
154
  #top-workspace {
155
  align-items: stretch;
 
826
  with gr.Column(scale=8, min_width=640, elem_id="outputs-column"):
827
  status_output = gr.Markdown()
828
 
829
+ with gr.Tabs(selected=DEPTH_VIEW_TAB_ID, elem_id="primary-view-tabs", **TABS_RENDER_KWARGS) as primary_view_tabs:
830
+ with gr.Tab("PCD Viewer", id=DEPTH_VIEW_TAB_ID, **TAB_RENDER_KWARGS):
831
  depth_model_3d = gr.Model3D(
832
  label="Point Cloud Viewer",
833
  display_mode="solid",
 
835
  height=700,
836
  elem_id="depth-model3d-viewer",
837
  )
838
+ with gr.Tab("GS Viewer", id=GS_VIEW_TAB_ID, **TAB_RENDER_KWARGS):
839
  gs_viewer_html = gr.HTML(elem_id="gs-viewer-html")
840
 
841
+ with gr.Tabs(elem_id="secondary-output-tabs", **TABS_RENDER_KWARGS):
842
+ with gr.Tab("Depth Analysis", **TAB_RENDER_KWARGS):
843
  depth_comparison = gr.Image(
844
  label="RGB vs Depth",
845
  type="filepath",
 
859
  height=260,
860
  elem_id="depth-preview",
861
  )
862
+ with gr.Tab("Downloads", **TAB_RENDER_KWARGS):
863
  with gr.Row():
864
  depth_download_files = gr.File(label="Depth Files", type="filepath")
865
  gs_download_files = gr.File(label="GS Files", type="filepath")