Spaces:
Running
on
Zero
Running
on
Zero
File size: 1,431 Bytes
e0483c8 bdabc21 ced4743 e0b5613 e0483c8 |
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 |
#!/usr/bin/env python3
"""
Pre-build script for Hugging Face Spaces
This script handles the installation of GroundingDINO and downloads required weights
"""
import os
import subprocess
import sys
from pathlib import Path
def run_command(cmd, cwd=None):
"""Run a shell command and handle errors"""
print(f"Running: {cmd}")
try:
result = subprocess.run(
cmd,
shell=True,
check=True,
cwd=cwd,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
)
print(result.stdout)
return True
except subprocess.CalledProcessError as e:
print(f"Error running command: {cmd}")
print(f"Error output: {e.stdout}")
return False
def setup_groundingdino():
"""Setup GroundingDINO"""
print("Setting up GroundingDINO...")
# Check if GroundingDINO directory already exists
# Install GroundingDINO
if not run_command("pip install -v -e ."):
return False
return True
def main():
"""Main setup function"""
print("Starting pre-build setup for Hugging Face Spaces...")
# Setup GroundingDINO
os.system("pip install -r requirements_hf.txt")
if not setup_groundingdino():
print("Failed to setup GroundingDINO")
sys.exit(1)
print("Pre-build setup completed successfully!")
if __name__ == "__main__":
main()
|