hljiang commited on
Commit
4c4eef7
·
verified ·
1 Parent(s): 5b2d8a0

Gradio 6.15 + module-level demo (PaGeR ZeroGPU pattern)

Browse files

Single on_run handler; backup at backup/app_pre_dap_debug.py

Files changed (3) hide show
  1. README.md +3 -2
  2. app.py +70 -70
  3. requirements.txt +1 -1
README.md CHANGED
@@ -4,7 +4,7 @@ emoji: 🌐
4
  colorFrom: blue
5
  colorTo: green
6
  sdk: gradio
7
- sdk_version: 5.50.0
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
@@ -28,7 +28,8 @@ Upload a 360° equirectangular image and click **Compute Depth** for a **scale-i
28
  This Space is tuned for **ZeroGPU** on `zero-a10g`:
29
 
30
  - **Large** checkpoint only (`DA360_large.pth`, ~1.3GB).
31
- - ZeroGPU: `@spaces.GPU(duration=120) compute_depth` bound **directly** to the Run button (HF requirement).
 
32
  - Weights from [`hljiang/DA360`](https://huggingface.co/hljiang/DA360) are **preloaded** (`preload_from_hub`) and packed on `cuda` at startup.
33
 
34
  **Tips**
 
4
  colorFrom: blue
5
  colorTo: green
6
  sdk: gradio
7
+ sdk_version: 6.15.1
8
  app_file: app.py
9
  pinned: false
10
  license: apache-2.0
 
28
  This Space is tuned for **ZeroGPU** on `zero-a10g`:
29
 
30
  - **Large** checkpoint only (`DA360_large.pth`, ~1.3GB).
31
+ - **Gradio 6.15** + module-level `demo` (same pattern as [PaGeR](https://huggingface.co/spaces/prs-eth/PaGeR)).
32
+ - ZeroGPU: `@spaces.GPU(duration=120) compute_depth` bound directly to **Compute Depth**.
33
  - Weights from [`hljiang/DA360`](https://huggingface.co/hljiang/DA360) are **preloaded** (`preload_from_hub`) and packed on `cuda` at startup.
34
 
35
  **Tips**
app.py CHANGED
@@ -723,68 +723,81 @@ def predict(image_path, model_path, scene_type="Outdoor"):
723
  return viewer_html, images
724
 
725
 
726
- def resolve_default_model(model_path=None):
727
- return DEFAULT_MODEL
 
 
 
 
 
 
 
728
 
729
 
730
- def build_demo(model_path=DEFAULT_MODEL):
731
- examples = get_example_images()
 
 
 
 
 
 
732
 
733
- with gr.Blocks(title="DA360 Demo", css=DEMO_CSS) as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
734
  gr.Markdown(
735
- textwrap.dedent(
736
- """
737
- # Depth Anything in 360° (debug)
738
- **Large** checkpoint only. DAP-style ZeroGPU inference;
739
- **scale-invariant** depth + KITTI colormap (not metric depth).
740
-
741
- [Project Page](https://insta360-research-team.github.io/DA360/) |
742
- [Paper](https://arxiv.org/abs/2512.22819) |
743
- [GitHub](https://github.com/insta360-research-team/DA360)
744
- """
745
- ).strip()
746
  )
747
- if not IS_HF_SPACE:
748
- gr.Markdown(
749
- "**Local mode:** expects `./checkpoints/DA360_large.pth`. "
750
- "Full UI backup: `backup/app_pre_dap_debug.py`."
751
- )
752
 
753
- panel_height = 360
754
-
755
- with gr.Row():
756
- with gr.Column(scale=1):
757
- image_input = gr.Image(
758
- label="Panoramic Input",
759
- type="filepath",
760
- height=panel_height,
761
- elem_classes=["panorama-panel"],
762
- )
763
- run_btn = gr.Button("Compute Depth", variant="primary")
764
- with gr.Column(scale=1):
765
- depth_output = gr.Image(
766
- label="Depth (KITTI colormap)",
767
- type="numpy",
768
- height=panel_height,
769
- elem_classes=["depth-panel"],
770
- )
771
-
772
- # ZeroGPU startup scan only sees @spaces.GPU on the function passed to .click().
773
- run_btn.click(
774
- fn=compute_depth,
775
- inputs=image_input,
776
- outputs=depth_output,
777
- )
778
 
779
- if examples:
780
- example_paths = [p[0] for p in examples]
781
- gr.Examples(
782
- examples=example_paths,
783
- inputs=image_input,
784
- cache_examples=False,
 
785
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
786
 
787
- return demo
 
 
 
 
 
788
 
789
 
790
  def resolve_server_port(preferred_port):
@@ -813,28 +826,15 @@ if __name__ == "__main__":
813
  parser.add_argument("--download", action="store_true", help="download missing checkpoints")
814
  args = parser.parse_args()
815
 
816
- startup_model = DEFAULT_MODEL
817
- should_fetch = args.download or IS_HF_SPACE or not os.path.exists(startup_model)
818
- if should_fetch:
819
- bootstrap_models(
820
- startup_model,
821
- download_all=bool(args.download),
822
- )
823
- elif os.path.exists(startup_model):
824
- preload_model_to_cpu(startup_model)
825
- if torch.cuda.is_available():
826
- move_model_to_gpu()
827
 
828
- demo = build_demo()
829
- ensure_viewer_html()
830
  server_port = resolve_server_port(args.server_port)
831
- # ssr_mode=False: older SSR paths could drop HF login identity and fall back
832
- # to the tiny anonymous ZeroGPU IP quota (see Gradio >=5.12 ZeroGPU fixes).
833
- demo.queue(default_concurrency_limit=1, max_size=16).launch(
834
  server_name=args.server_name,
835
  server_port=server_port,
836
  share=args.share,
837
  allowed_paths=[os.path.abspath(CACHE_DIR)],
838
  show_error=True,
839
- ssr_mode=False,
840
  )
 
723
  return viewer_html, images
724
 
725
 
726
+ def _startup(download_all=False):
727
+ """Load Large weights and pack on cuda (module scope — PaGeR / ZeroGPU rule)."""
728
+ startup_model = DEFAULT_MODEL
729
+ if IS_HF_SPACE or not os.path.exists(startup_model):
730
+ bootstrap_models(startup_model, download_all=download_all)
731
+ elif os.path.exists(startup_model):
732
+ preload_model_to_cpu(startup_model)
733
+ if torch.cuda.is_available():
734
+ move_model_to_gpu()
735
 
736
 
737
+ if IS_HF_SPACE:
738
+ print(
739
+ f"[startup] SPACE_ID={os.environ.get('SPACE_ID')} "
740
+ f"SPACES_ZERO_GPU={os.environ.get('SPACES_ZERO_GPU')}",
741
+ flush=True,
742
+ )
743
+ _startup()
744
+ ensure_viewer_html()
745
 
746
+ _EXAMPLE_PATHS = [p[0] for p in get_example_images()]
747
+
748
+ # PaGeR pattern: module-level Blocks so ZeroGPU startup scan sees @spaces.GPU handlers.
749
+ with gr.Blocks(title="DA360 Demo") as demo:
750
+ gr.HTML(f"<style>{DEMO_CSS}</style>")
751
+ gr.Markdown(
752
+ textwrap.dedent(
753
+ """
754
+ # Depth Anything in 360° (debug)
755
+ **Large** checkpoint only. ZeroGPU inference;
756
+ **scale-invariant** depth + KITTI colormap (not metric depth).
757
+
758
+ [Project Page](https://insta360-research-team.github.io/DA360/) |
759
+ [Paper](https://arxiv.org/abs/2512.22819) |
760
+ [GitHub](https://github.com/insta360-research-team/DA360)
761
+ """
762
+ ).strip()
763
+ )
764
+ if not IS_HF_SPACE:
765
  gr.Markdown(
766
+ "**Local mode:** expects `./checkpoints/DA360_large.pth`. "
767
+ "Full UI backup: `backup/app_pre_dap_debug.py`."
 
 
 
 
 
 
 
 
 
768
  )
 
 
 
 
 
769
 
770
+ panel_height = 360
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
771
 
772
+ with gr.Row():
773
+ with gr.Column(scale=1):
774
+ image_input = gr.Image(
775
+ label="Panoramic Input",
776
+ type="filepath",
777
+ height=panel_height,
778
+ elem_classes=["panorama-panel"],
779
  )
780
+ run_btn = gr.Button("Compute Depth", variant="primary")
781
+ with gr.Column(scale=1):
782
+ depth_output = gr.Image(
783
+ label="Depth (KITTI colormap)",
784
+ type="numpy",
785
+ height=panel_height,
786
+ elem_classes=["depth-panel"],
787
+ )
788
+
789
+ run_btn.click(
790
+ fn=compute_depth,
791
+ inputs=image_input,
792
+ outputs=depth_output,
793
+ )
794
 
795
+ if _EXAMPLE_PATHS:
796
+ gr.Examples(
797
+ examples=_EXAMPLE_PATHS,
798
+ inputs=image_input,
799
+ cache_examples=False,
800
+ )
801
 
802
 
803
  def resolve_server_port(preferred_port):
 
826
  parser.add_argument("--download", action="store_true", help="download missing checkpoints")
827
  args = parser.parse_args()
828
 
829
+ if not IS_HF_SPACE:
830
+ _startup(download_all=bool(args.download))
831
+ ensure_viewer_html()
 
 
 
 
 
 
 
 
832
 
 
 
833
  server_port = resolve_server_port(args.server_port)
834
+ demo.queue(default_concurrency_limit=1).launch(
 
 
835
  server_name=args.server_name,
836
  server_port=server_port,
837
  share=args.share,
838
  allowed_paths=[os.path.abspath(CACHE_DIR)],
839
  show_error=True,
 
840
  )
requirements.txt CHANGED
@@ -1,7 +1,7 @@
1
  torch==2.8.0
2
  torchvision==0.23.0
3
  spaces
4
- gradio==5.50.0
5
  huggingface_hub>=0.33.5
6
  matplotlib
7
  scipy
 
1
  torch==2.8.0
2
  torchvision==0.23.0
3
  spaces
4
+ gradio>=6.15.1
5
  huggingface_hub>=0.33.5
6
  matplotlib
7
  scipy