#!/usr/bin/env python3 """ Universal Fast Dubbing Backend Setup Script """ import os import sys import subprocess def check_python_version(): """Check if Python version is 3.8 or higher""" if sys.version_info < (3, 8): print("āŒ Python 3.8 or higher is required") sys.exit(1) print(f"āœ… Python {sys.version_info.major}.{sys.version_info.minor} detected") def create_venv(): """Create virtual environment""" print("\nšŸ“¦ Creating virtual environment...") try: subprocess.run([sys.executable, "-m", "venv", "venv"], check=True) print("āœ… Virtual environment created") except subprocess.CalledProcessError: print("āŒ Failed to create virtual environment") sys.exit(1) def install_dependencies(): """Install required dependencies""" print("\nšŸ“„ Installing dependencies...") # Determine pip path based on OS if sys.platform == "win32": pip_path = os.path.join("venv", "Scripts", "pip") else: pip_path = os.path.join("venv", "bin", "pip") try: subprocess.run([pip_path, "install", "-r", "requirements.txt"], check=True) print("āœ… Dependencies installed") except subprocess.CalledProcessError: print("āŒ Failed to install dependencies") sys.exit(1) def check_ffmpeg(): """Check if FFmpeg is installed""" print("\nšŸŽµ Checking FFmpeg installation...") try: subprocess.run(["ffmpeg", "-version"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True) print("āœ… FFmpeg is installed") except (subprocess.CalledProcessError, FileNotFoundError): print("āš ļø FFmpeg not found. Please install FFmpeg:") print(" - Windows: https://ffmpeg.org/download.html") print(" - macOS: brew install ffmpeg") print(" - Linux: sudo apt-get install ffmpeg") def create_env_file(): """Create .env file from template""" print("\nāš™ļø Setting up environment configuration...") if not os.path.exists(".env"): if os.path.exists(".env.example"): with open(".env.example", "r") as src: with open(".env", "w") as dst: dst.write(src.read()) print("āœ… .env file created from template") print("āš ļø Please edit .env and add your GROQ_API_KEY") else: print("āŒ .env.example not found") else: print("āœ… .env file already exists") def main(): """Main setup function""" print("=" * 50) print("Universal Fast Dubbing Backend Setup") print("=" * 50) check_python_version() create_venv() install_dependencies() check_ffmpeg() create_env_file() print("\n" + "=" * 50) print("āœ… Setup complete!") print("=" * 50) print("\nNext steps:") print("1. Edit backend/.env and add your GROQ_API_KEY") print("2. Activate virtual environment:") if sys.platform == "win32": print(" venv\\Scripts\\activate") else: print(" source venv/bin/activate") print("3. Run the application:") print(" python app.py") if __name__ == "__main__": main()