Spaces:
Running
Running
| #!/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() | |