Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,56 +12,48 @@ def cpu_run_inference(self, *args, **kwargs):
|
|
| 12 |
# Replace original method
|
| 13 |
ModelInference.run_inference = cpu_run_inference
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
)
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
examples_exist = os.path.exists(examples_dir)
|
| 31 |
-
|
| 32 |
-
cache_examples_env = os.environ.get("DA3_CACHE_EXAMPLES", "").lower()
|
| 33 |
-
if cache_examples_env in ("false", "0", "no"):
|
| 34 |
-
cache_examples = False
|
| 35 |
-
elif cache_examples_env in ("true", "1", "yes"):
|
| 36 |
-
cache_examples = True
|
| 37 |
-
else:
|
| 38 |
-
cache_examples = examples_exist
|
| 39 |
-
|
| 40 |
-
cache_gs_tag = os.environ.get("DA3_CACHE_GS_TAG", "dl3dv")
|
| 41 |
-
|
| 42 |
print("🚀 Launching Depth Anything 3 (CPU-only) on Hugging Face Spaces...")
|
| 43 |
-
print(f"📦 Model Directory: {model_dir}")
|
| 44 |
-
print(f"📁 Workspace Directory: {workspace_dir}")
|
| 45 |
-
print(f"🖼️ Gallery Directory: {gallery_dir}")
|
| 46 |
-
print(f"💾 Cache Examples: {cache_examples}")
|
| 47 |
-
if cache_examples and cache_gs_tag:
|
| 48 |
-
print(f"🏷️ Cache GS Tag: '{cache_gs_tag}'")
|
| 49 |
-
|
| 50 |
-
if cache_examples:
|
| 51 |
-
print("\n" + "=" * 60)
|
| 52 |
-
print("Pre-caching mode enabled (CPU)")
|
| 53 |
-
print("=" * 60)
|
| 54 |
-
app.cache_examples(
|
| 55 |
-
show_cam=True,
|
| 56 |
-
filter_black_bg=False,
|
| 57 |
-
filter_white_bg=False,
|
| 58 |
-
save_percentage=5.0,
|
| 59 |
-
num_max_points=1000,
|
| 60 |
-
cache_gs_tag=cache_gs_tag,
|
| 61 |
-
gs_trj_mode="smooth",
|
| 62 |
-
gs_video_quality="low",
|
| 63 |
-
)
|
| 64 |
-
|
| 65 |
app.launch(
|
| 66 |
host="0.0.0.0",
|
| 67 |
port=7860,
|
|
|
|
| 12 |
# Replace original method
|
| 13 |
ModelInference.run_inference = cpu_run_inference
|
| 14 |
|
| 15 |
+
# Directories
|
| 16 |
+
model_dir = os.environ.get("DA3_MODEL_DIR", "depth-anything/DA3NESTED-GIANT-LARGE")
|
| 17 |
+
workspace_dir = os.environ.get("DA3_WORKSPACE_DIR", "workspace/gradio")
|
| 18 |
+
gallery_dir = os.environ.get("DA3_GALLERY_DIR", "workspace/gallery")
|
| 19 |
+
|
| 20 |
+
os.makedirs(workspace_dir, exist_ok=True)
|
| 21 |
+
os.makedirs(gallery_dir, exist_ok=True)
|
| 22 |
+
|
| 23 |
+
# Global app object for Hugging Face Spaces
|
| 24 |
+
app = DepthAnything3App(
|
| 25 |
+
model_dir=model_dir,
|
| 26 |
+
workspace_dir=workspace_dir,
|
| 27 |
+
gallery_dir=gallery_dir
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
# Optional: pre-cache examples
|
| 31 |
+
examples_dir = os.path.join(workspace_dir, "examples")
|
| 32 |
+
examples_exist = os.path.exists(examples_dir)
|
| 33 |
+
cache_examples_env = os.environ.get("DA3_CACHE_EXAMPLES", "").lower()
|
| 34 |
+
if cache_examples_env in ("false", "0", "no"):
|
| 35 |
+
cache_examples = False
|
| 36 |
+
elif cache_examples_env in ("true", "1", "yes"):
|
| 37 |
+
cache_examples = True
|
| 38 |
+
else:
|
| 39 |
+
cache_examples = examples_exist
|
| 40 |
+
|
| 41 |
+
cache_gs_tag = os.environ.get("DA3_CACHE_GS_TAG", "dl3dv")
|
| 42 |
+
|
| 43 |
+
if cache_examples:
|
| 44 |
+
app.cache_examples(
|
| 45 |
+
show_cam=True,
|
| 46 |
+
filter_black_bg=False,
|
| 47 |
+
filter_white_bg=False,
|
| 48 |
+
save_percentage=5.0,
|
| 49 |
+
num_max_points=1000,
|
| 50 |
+
cache_gs_tag=cache_gs_tag,
|
| 51 |
+
gs_trj_mode="smooth",
|
| 52 |
+
gs_video_quality="low",
|
| 53 |
)
|
| 54 |
+
|
| 55 |
+
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
print("🚀 Launching Depth Anything 3 (CPU-only) on Hugging Face Spaces...")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
app.launch(
|
| 58 |
host="0.0.0.0",
|
| 59 |
port=7860,
|