File size: 1,787 Bytes
4845d25
d3d9a93
 
4845d25
d3d9a93
4845d25
 
d3d9a93
 
 
4845d25
d3d9a93
 
 
 
 
 
 
1ecbfb8
 
d3d9a93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1ecbfb8
d3d9a93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1ecbfb8
 
d3d9a93
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
import os
import torch
import gradio as gr

from depth_anything_3.model import DepthAnything3


# ---------------------------------------------------------
#  CPU-safe DepthAnything3 loader
# ---------------------------------------------------------

def load_model_cpu(model_dir):
    print("🔄 Loading DepthAnything3 model on CPU...")
    model = DepthAnything3.from_pretrained(model_dir, config_name="config.json")
    model.to("cpu")
    model.eval()
    print("✅ Model ready on CPU")
    return model


MODEL_DIR = os.environ.get("DA3_MODEL_DIR", "depth-anything/DA3NESTED-GIANT-LARGE")
model = load_model_cpu(MODEL_DIR)


# ---------------------------------------------------------
#  CPU-safe inference (single image only)
# ---------------------------------------------------------

def run_depth(img):
    """
    CPU version of depth inference.
    No batching, no multiview, no GS, no reconstruction.
    """
    if img is None:
        return None

    with torch.no_grad():
        depth = model.infer_image(img, device="cpu")

    return depth


# ---------------------------------------------------------
#  Minimal Gradio UI (fast startup)
# ---------------------------------------------------------

title = "Depth Anything 3 — CPU Mode (Safe HF Version)"
description = """
This Hugging Face Space runs **DepthAnything3** in CPU-only mode.
Only single-image depth inference is enabled.  
All heavy multiview / GS / reconstruction features were removed so the Space can boot on CPU.
"""

demo = gr.Interface(
    fn=run_depth,
    inputs=gr.Image(type="pil", label="Upload an image"),
    outputs=gr.Image(label="Predicted Depth"),
    title=title,
    description=description,
)

if __name__ == "__main__":
    demo.launch(server_name="0.0.0.0", server_port=7860)