Spaces:
Running
Running
| 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 | |
| ) | |