Download app.py from pedroivospatial/pis-spatial-intelligence-lab: direct link, hf CLI and curl.
- Browser
- Download file 3.89 kB
-
https://huggingface.co/spaces/pedroivospatial/pis-spatial-intelligence-lab/resolve/main/app.py
- Command line
-
hf download hf://spaces/pedroivospatial/pis-spatial-intelligence-lab/app.py
-
curl -L -o app.py https://huggingface.co/spaces/pedroivospatial/pis-spatial-intelligence-lab/resolve/main/app.py
3.89 kB
| from functools import lru_cache | |
| import gradio as gr | |
| from transformers import pipeline | |
| from lab_core import SAMPLE_LABELS, analyze_depth_signal, colorize_depth, generate_scene | |
| MODEL_ID = "depth-anything/Depth-Anything-V2-Small-hf" | |
| def get_depth_pipeline(): | |
| """Load the reviewed Apache-2.0 model once per Space process.""" | |
| return pipeline(task="depth-estimation", model=MODEL_ID, device=-1) | |
| def select_sample(sample_label: str): | |
| key = SAMPLE_LABELS.get(sample_label, "training_room") | |
| return ( | |
| generate_scene(key), | |
| None, | |
| "Select **Run reviewed model** to produce a relative-depth preview. " | |
| "The scene is synthetic and contains no client data.", | |
| ) | |
| def run_analysis(sample_label: str): | |
| key = SAMPLE_LABELS.get(sample_label, "training_room") | |
| source = generate_scene(key) | |
| try: | |
| result = get_depth_pipeline()(source) | |
| raw_depth = result["depth"] | |
| depth_preview = colorize_depth(raw_depth) | |
| report = analyze_depth_signal(raw_depth, sample_label, MODEL_ID) | |
| except Exception as exc: # Keep the public demo honest and inspectable. | |
| depth_preview = None | |
| report = ( | |
| "### Model unavailable\n\n" | |
| "The synthetic source remains visible, but the reviewed model did not " | |
| "complete. No fallback result is presented as model output.\n\n" | |
| f"Technical class: `{type(exc).__name__}`. Try again after the Space restarts." | |
| ) | |
| return source, depth_preview, report | |
| CSS = """ | |
| .gradio-container {max-width: 1180px !important; margin: 0 auto;} | |
| .pis-hero {padding: 18px 22px; border: 1px solid rgba(100,116,139,.35); | |
| border-radius: 18px; background: linear-gradient(135deg,#07111f,#102a43); color:#f8fafc;} | |
| .pis-hero h1 {margin: 0 0 8px 0; font-size: 2rem; color:#f8fafc !important;} | |
| .pis-hero p {margin: 0; color:#dbeafe !important;} | |
| .boundary {border-left: 4px solid #38bdf8; padding-left: 14px;} | |
| """ | |
| with gr.Blocks(title="PIS Spatial Intelligence Lab") as demo: | |
| gr.HTML( | |
| """ | |
| <section class="pis-hero"> | |
| <h1>PIS Spatial Intelligence Lab</h1> | |
| <p>Privacy-safe experiments for reality capture, depth and spatial understanding.</p> | |
| </section> | |
| """ | |
| ) | |
| gr.Markdown( | |
| """ | |
| <div class="boundary"> | |
| **Public research preview.** Choose one procedurally generated scene. There is no | |
| upload control and no real venue or client material in this application. The output | |
| is relative depth—not measurements, a survey, or a floor plan. | |
| </div> | |
| """ | |
| ) | |
| sample = gr.Dropdown( | |
| choices=list(SAMPLE_LABELS.keys()), | |
| value="Synthetic training venue", | |
| label="Synthetic scene", | |
| interactive=True, | |
| ) | |
| run = gr.Button("Run reviewed model", variant="primary") | |
| with gr.Row(): | |
| source = gr.Image( | |
| value=generate_scene("training_room"), | |
| label="Synthetic source", | |
| interactive=False, | |
| type="pil", | |
| ) | |
| depth = gr.Image( | |
| label="Relative-depth preview", | |
| interactive=False, | |
| type="pil", | |
| ) | |
| report = gr.Markdown( | |
| "Select **Run reviewed model** to produce a relative-depth preview. " | |
| "The scene is synthetic and contains no client data." | |
| ) | |
| gr.Markdown( | |
| """ | |
| --- | |
| Model: [`depth-anything/Depth-Anything-V2-Small-hf`](https://huggingface.co/depth-anything/Depth-Anything-V2-Small-hf) | |
| · License metadata: Apache-2.0 · [Pedro Ivo Spatial](https://pedroivospatial.nl) | |
| """ | |
| ) | |
| sample.change(select_sample, inputs=sample, outputs=[source, depth, report]) | |
| run.click(run_analysis, inputs=sample, outputs=[source, depth, report]) | |
| if __name__ == "__main__": | |
| demo.queue(max_size=8).launch(css=CSS) | |