| | |
| | """ |
| | Main entry point for the music source separation application |
| | """ |
| |
|
| | import os |
| | import sys |
| | import argparse |
| | from pathlib import Path |
| | from config import BASE_DIR |
| |
|
| | def setup_environment(): |
| | """Setup the environment and install dependencies""" |
| | print("π§ Setting up environment...") |
| | |
| | |
| | print("π¦ Installing dependencies...") |
| | exit_code = os.system(f"{sys.executable} -m pip install -r requirements.txt") |
| | |
| | if exit_code != 0: |
| | print("β Failed to install dependencies") |
| | return False |
| | |
| | |
| | print("π Creating directory structure...") |
| | directories = [ |
| | BASE_DIR / "audio_samples", |
| | BASE_DIR / "separated_audio", |
| | BASE_DIR / "models", |
| | BASE_DIR / "logs", |
| | BASE_DIR / "examples" |
| | ] |
| | |
| | for directory in directories: |
| | directory.mkdir(exist_ok=True) |
| | print(f"β Created {directory}") |
| | |
| | |
| | print("π€ Downloading pre-trained models...") |
| | try: |
| | from download_models import download_models |
| | if download_models(): |
| | print("β
Models downloaded successfully") |
| | else: |
| | print("β Model download failed") |
| | return False |
| | except Exception as e: |
| | print(f"β Error downloading models: {e}") |
| | return False |
| | |
| | print("β
Environment setup complete!") |
| | return True |
| |
|
| | def run_application(host="0.0.0.0", port=7860, share=False): |
| | """Run the Gradio application""" |
| | print("π Starting Music Source Separator application...") |
| | print(f"π Access the interface at: http://{host}:{port}") |
| | |
| | try: |
| | import app |
| | app.demo.launch( |
| | server_name=host, |
| | server_port=port, |
| | share=share, |
| | show_error=True |
| | ) |
| | except Exception as e: |
| | print(f"β Failed to start application: {e}") |
| | return False |
| | |
| | return True |
| |
|
| | def main(): |
| | """Main entry point""" |
| | parser = argparse.ArgumentParser(description="Music Source Separator") |
| | parser.add_argument( |
| | "command", |
| | nargs="?", |
| | default="run", |
| | choices=["setup", "run"], |
| | help="Command to execute (setup: install dependencies, run: start app)" |
| | ) |
| | parser.add_argument( |
| | "--host", |
| | default="0.0.0.0", |
| | help="Host to run the server on" |
| | ) |
| | parser.add_argument( |
| | "--port", |
| | type=int, |
| | default=7860, |
| | help="Port to run the server on" |
| | ) |
| | parser.add_argument( |
| | "--share", |
| | action="store_true", |
| | help="Create public share link" |
| | ) |
| | |
| | args = parser.parse_args() |
| | |
| | if args.command == "setup": |
| | success = setup_environment() |
| | sys.exit(0 if success else 1) |
| | else: |
| | success = run_application(args.host, args.port, args.share) |
| | sys.exit(0 if success else 1) |
| |
|
| | if __name__ == "__main__": |
| | main() |