File size: 2,354 Bytes
4845d25
 
 
 
cfc7d65
4845d25
 
cfc7d65
 
4845d25
 
cfc7d65
 
4845d25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6a8ae2c
 
 
 
 
 
 
 
 
 
 
 
 
cfc7d65
4845d25
 
 
6a8ae2c
cfc7d65
 
6a8ae2c
 
 
cfc7d65
6a8ae2c
 
 
 
 
 
 
 
 
 
 
4845d25
 
cfc7d65
 
 
4845d25
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
import os
from depth_anything_3.app.gradio_app import DepthAnything3App
from depth_anything_3.app.modules.model_inference import ModelInference

# Remove GPU decorator; run normally on CPU
original_run_inference = ModelInference.run_inference

def cpu_run_inference(self, *args, **kwargs):
    """CPU-only inference"""
    return original_run_inference(self, *args, **kwargs)

# Replace original method
ModelInference.run_inference = cpu_run_inference

if __name__ == "__main__":
    model_dir = os.environ.get("DA3_MODEL_DIR", "depth-anything/DA3NESTED-GIANT-LARGE")
    workspace_dir = os.environ.get("DA3_WORKSPACE_DIR", "workspace/gradio")
    gallery_dir = os.environ.get("DA3_GALLERY_DIR", "workspace/gallery")
    
    os.makedirs(workspace_dir, exist_ok=True)
    os.makedirs(gallery_dir, exist_ok=True)
    
    app = DepthAnything3App(
        model_dir=model_dir,
        workspace_dir=workspace_dir,
        gallery_dir=gallery_dir
    )
    
    examples_dir = os.path.join(workspace_dir, "examples")
    examples_exist = os.path.exists(examples_dir)
    
    cache_examples_env = os.environ.get("DA3_CACHE_EXAMPLES", "").lower()
    if cache_examples_env in ("false", "0", "no"):
        cache_examples = False
    elif cache_examples_env in ("true", "1", "yes"):
        cache_examples = True
    else:
        cache_examples = examples_exist
    
    cache_gs_tag = os.environ.get("DA3_CACHE_GS_TAG", "dl3dv")
    
    print("🚀 Launching Depth Anything 3 (CPU-only) on Hugging Face Spaces...")
    print(f"📦 Model Directory: {model_dir}")
    print(f"📁 Workspace Directory: {workspace_dir}")
    print(f"🖼️  Gallery Directory: {gallery_dir}")
    print(f"💾 Cache Examples: {cache_examples}")
    if cache_examples and cache_gs_tag:
        print(f"🏷️  Cache GS Tag: '{cache_gs_tag}'")
    
    if cache_examples:
        print("\n" + "=" * 60)
        print("Pre-caching mode enabled (CPU)")
        print("=" * 60)
        app.cache_examples(
            show_cam=True,
            filter_black_bg=False,
            filter_white_bg=False,
            save_percentage=5.0,
            num_max_points=1000,
            cache_gs_tag=cache_gs_tag,
            gs_trj_mode="smooth",
            gs_video_quality="low",
        )
    
    app.launch(
        host="0.0.0.0",
        port=7860,
        share=False
    )