File size: 3,893 Bytes
573b479
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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"


@lru_cache(maxsize=1)
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)