Spaces:
Build error
Build error
| #!/usr/bin/env python3 | |
| """ | |
| Launch script for Enhanced Audio Separator Demo | |
| Provides easy startup options and system checks | |
| """ | |
| import os | |
| import sys | |
| import subprocess | |
| import argparse | |
| import time | |
| from pathlib import Path | |
| def check_dependencies(): | |
| """Check if required dependencies are installed""" | |
| required_packages = [ | |
| "torch", "audio_separator", "gradio", "librosa", | |
| "soundfile", "pydub", "onnxruntime" | |
| ] | |
| missing_packages = [] | |
| for package in required_packages: | |
| try: | |
| __import__(package) | |
| except ImportError: | |
| missing_packages.append(package) | |
| return missing_packages | |
| def check_system_requirements(): | |
| """Check system requirements and hardware acceleration""" | |
| try: | |
| import torch | |
| import psutil | |
| # Check Python version | |
| python_version = sys.version_info | |
| if python_version < (3, 10): | |
| print("β οΈ Warning: Python 3.10+ recommended for best performance") | |
| else: | |
| print(f"β Python {python_version.major}.{python_version.minor} detected") | |
| # Check PyTorch | |
| print(f"β PyTorch {torch.__version__} detected") | |
| # Check CUDA | |
| if torch.cuda.is_available(): | |
| print(f"β CUDA {torch.version.cuda} available with {torch.cuda.device_count()} GPU(s)") | |
| for i in range(torch.cuda.device_count()): | |
| print(f" GPU {i}: {torch.cuda.get_device_name(i)}") | |
| else: | |
| print("βΉοΈ CUDA not available - will use CPU processing") | |
| # Check Apple Silicon | |
| if hasattr(torch.backends, "mps") and torch.backends.mps.is_available(): | |
| print("β Apple Silicon (MPS) acceleration available") | |
| # Check memory | |
| memory = psutil.virtual_memory() | |
| print(f"πΎ System memory: {memory.total // (1024**3)} GB total, {memory.available // (1024**3)} GB available") | |
| # Check disk space | |
| disk = psutil.disk_usage('.') | |
| print(f"πΏ Disk space: {disk.free // (1024**3)} GB available") | |
| except Exception as e: | |
| print(f"β οΈ Error checking system: {e}") | |
| def install_dependencies(): | |
| """Install missing dependencies""" | |
| print("π¦ Installing missing dependencies...") | |
| try: | |
| subprocess.check_call([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"]) | |
| print("β Dependencies installed successfully") | |
| return True | |
| except subprocess.CalledProcessError as e: | |
| print(f"β Failed to install dependencies: {e}") | |
| return False | |
| def setup_directories(): | |
| """Create necessary directories""" | |
| directories = [ | |
| "outputs", | |
| "temp", | |
| "models" | |
| ] | |
| for directory in directories: | |
| Path(directory).mkdir(exist_ok=True) | |
| print(f"π Created/verified directory: {directory}") | |
| def launch_demo(port=7860, share=False, debug=False): | |
| """Launch the Gradio demo""" | |
| print("π Launching Enhanced Audio Separator Demo...") | |
| print(f"π Server will be available at: http://localhost:{port}") | |
| if share: | |
| print("π Public sharing enabled") | |
| if debug: | |
| print("π Debug mode enabled") | |
| try: | |
| from app import create_interface | |
| interface = create_interface() | |
| interface.launch( | |
| server_name="0.0.0.0", | |
| server_port=port, | |
| share=share, | |
| show_error=debug, | |
| quiet=not debug, | |
| inbrowser=True | |
| ) | |
| except KeyboardInterrupt: | |
| print("\nπ Demo stopped by user") | |
| except Exception as e: | |
| print(f"β Error launching demo: {e}") | |
| if debug: | |
| import traceback | |
| traceback.print_exc() | |
| def main(): | |
| parser = argparse.ArgumentParser(description="Enhanced Audio Separator Demo Launcher") | |
| parser.add_argument("--port", type=int, default=7860, help="Port to run the demo on (default: 7860)") | |
| parser.add_argument("--share", action="store_true", help="Enable public sharing") | |
| parser.add_argument("--debug", action="store_true", help="Enable debug mode") | |
| parser.add_argument("--check-only", action="store_true", help="Only check system requirements") | |
| parser.add_argument("--install-deps", action="store_true", help="Install dependencies and exit") | |
| parser.add_argument("--setup-only", action="store_true", help="Setup directories and check requirements only") | |
| args = parser.parse_args() | |
| print("=" * 60) | |
| print("π΅ Enhanced Audio Separator Demo Launcher") | |
| print("=" * 60) | |
| # Check system requirements | |
| check_system_requirements() | |
| print() | |
| if args.check_only: | |
| return | |
| # Check dependencies | |
| print("π Checking dependencies...") | |
| missing = check_dependencies() | |
| if missing: | |
| print(f"β Missing packages: {', '.join(missing)}") | |
| if args.install_deps: | |
| if not install_dependencies(): | |
| sys.exit(1) | |
| else: | |
| print("Run with --install-deps to install missing packages, or:") | |
| print(f"pip install {' '.join(missing)}") | |
| sys.exit(1) | |
| else: | |
| print("β All dependencies satisfied") | |
| print() | |
| # Setup directories | |
| if not args.setup_only: | |
| setup_directories() | |
| print() | |
| if args.setup_only: | |
| return | |
| # Launch demo | |
| launch_demo(port=args.port, share=args.share, debug=args.debug) | |
| if __name__ == "__main__": | |
| main() |