harshilawign's picture
Switch HuggingFace Space to simplified version
8cfd98b
# Copyright (c) 2025 ByteDance Ltd. and/or its affiliates
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Hugging Face Spaces App for Depth Anything 3 - Simplified Version.
This version uses the simplified interface (ZIP in → ZIP out) with
the @spaces.GPU decorator for GPU resource management on HF Spaces.
"""
import os
import spaces
import torch
# Import the simplified app
from simple_app import SimpleDepthApp
# Get original model loading method
original_load_model = SimpleDepthApp.load_model
# Apply @spaces.GPU decorator to model loading
@spaces.GPU(duration=180) # Request GPU for up to 180 seconds
def gpu_load_model_wrapper(self):
"""GPU-accelerated model loading with Spaces decorator."""
return original_load_model(self)
# Replace with GPU-decorated version
SimpleDepthApp.load_model = gpu_load_model_wrapper
# Apply @spaces.GPU decorator to process_zip method
original_process_zip = SimpleDepthApp.process_zip
@spaces.GPU(duration=300) # Request GPU for up to 5 minutes per batch
def gpu_process_zip_wrapper(self, zip_file):
"""GPU-accelerated ZIP processing with Spaces decorator."""
return original_process_zip(self, zip_file)
# Replace with GPU-decorated version
SimpleDepthApp.process_zip = gpu_process_zip_wrapper
if __name__ == "__main__":
# Configure for HuggingFace Spaces
model_dir = os.environ.get("DA3_MODEL_DIR", "depth-anything/DA3NESTED-GIANT-LARGE")
print("🚀 Starting Simplified Depth Anything 3 on HuggingFace Spaces...")
print(f"📦 Model: {model_dir}")
print(f"💾 GPU available: {torch.cuda.is_available()}")
# Initialize and launch
app = SimpleDepthApp(model_dir=model_dir)
app.launch(
server_name="0.0.0.0",
server_port=7860,
share=False
)