From 5f2e54552cadc29fa96b6119fbf9636dfcdd4521 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 25 May 2025 18:42:44 +0000 Subject: [PATCH] feat: Add Windows setup and run scripts, update README This commit introduces automation scripts for Windows users and updates the README.md accordingly. New/Modified Windows Scripts: - setup_windows.bat: New script to automate Python checks, ffmpeg warning, virtual environment (.venv) creation, pip upgrade, and dependency installation. - run_windows.bat: New script to run the application with CPU execution provider by default, activating .venv. - run-cuda.bat: Updated to use .venv and pass arguments. - run-directml.bat: Updated to use .venv and pass arguments. README.md Changes: - Updated the "For Windows:" section under "Installation (Manual)" to detail the new automated setup using setup_windows.bat and the revised run scripts. - Recommended Python 3.10 for Windows for best compatibility. - Provided updated manual setup notes for Windows, including a PowerShell command for ffmpeg installation and using .venv for consistency. - Ensured the general Python recommendation in the manual setup prerequisites also mentions Python 3.10. --- README.md | 57 ++++++++++++++++++++++++++++++---- run-cuda.bat | 17 +++++++++- run-directml.bat | 17 +++++++++- run_windows.bat | 20 ++++++++++++ setup_windows.bat | 79 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 182 insertions(+), 8 deletions(-) create mode 100644 run_windows.bat create mode 100644 setup_windows.bat diff --git a/README.md b/README.md index 589b0ac..f6d3e9b 100644 --- a/README.md +++ b/README.md @@ -134,12 +134,57 @@ Place these files in the "**models**" folder. We highly recommend using a `venv` to avoid issues. -For Windows: -```bash -python -m venv venv -venv\Scripts\activate -pip install -r requirements.txt -``` +**For Windows:** + +It is highly recommended to use Python 3.10 for Windows for best compatibility with all features and dependencies. + +**Automated Setup (Recommended):** + +1. **Run the setup script:** + Double-click `setup_windows.bat` or run it from your command prompt: + ```batch + setup_windows.bat + ``` + This script will: + * Check if Python is in your PATH. + * Warn if `ffmpeg` is not found (see "Manual Steps / Notes" below for ffmpeg help). + * Create a virtual environment named `.venv` (consistent with macOS setup). + * Activate the virtual environment for the script's session. + * Upgrade pip. + * Install Python packages from `requirements.txt`. + Wait for the script to complete. It will pause at the end; press any key to close the window if you double-clicked it. + +2. **Run the application:** + After setup, use the provided `.bat` scripts to run the application. These scripts automatically activate the correct virtual environment: + * `run_windows.bat`: Runs the application with the CPU execution provider by default. This is a good starting point if you don't have a dedicated GPU or are unsure. + * `run-cuda.bat`: Runs with the CUDA (NVIDIA GPU) execution provider. Requires an NVIDIA GPU and CUDA Toolkit installed (see GPU Acceleration section). + * `run-directml.bat`: Runs with the DirectML (AMD/Intel GPU on Windows) execution provider. + + Example: Double-click `run_windows.bat` to launch the UI, or run from a command prompt: + ```batch + run_windows.bat --source path\to\your_face.jpg --target path\to\video.mp4 + ``` + +**Manual Steps / Notes:** + +* **Python:** Ensure Python 3.10 is installed and added to your system's PATH. You can download it from [python.org](https://www.python.org/downloads/). +* **ffmpeg:** + * `ffmpeg` is required for video processing. The `setup_windows.bat` script will warn if it's not found in your PATH. + * An easy way to install `ffmpeg` on Windows is to open PowerShell as Administrator and run: + ```powershell + Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')); choco install ffmpeg -y + ``` + Alternatively, download from [ffmpeg.org](https://ffmpeg.org/download.html), extract the files, and add the `bin` folder (containing `ffmpeg.exe`) to your system's PATH environment variable. The original README also linked to a [YouTube guide](https://www.youtube.com/watch?v=OlNWCpFdVMA) or `iex (irm ffmpeg.tc.ht)` via PowerShell. +* **Visual Studio Runtimes:** If you encounter errors during `pip install` for packages that compile C code (e.g., some scientific computing or image processing libraries), you might need the [Visual Studio Build Tools (or Runtimes)](https://visualstudio.microsoft.com/visual-cpp-build-tools/). Ensure "C++ build tools" (or similar workload) are selected during installation. +* **Virtual Environment (Manual Alternative):** If you prefer to set up the virtual environment manually instead of using `setup_windows.bat`: + ```batch + python -m venv .venv + .venv\Scripts\activate.bat + python -m pip install --upgrade pip + python -m pip install -r requirements.txt + ``` + (The new automated scripts use `.venv` as the folder name for consistency with the macOS setup). + For Linux: ```bash # Ensure you use the installed Python 3.10 diff --git a/run-cuda.bat b/run-cuda.bat index 93042a7..a638b99 100644 --- a/run-cuda.bat +++ b/run-cuda.bat @@ -1 +1,16 @@ -python run.py --execution-provider cuda +@echo off +set VENV_DIR=.venv + +:: Check if virtual environment exists +if not exist "%VENV_DIR%\Scripts\activate.bat" ( + echo Virtual environment '%VENV_DIR%' not found. + echo Please run setup_windows.bat first. + pause + exit /b 1 +) + +echo Activating virtual environment... +call "%VENV_DIR%\Scripts\activate.bat" + +echo Starting the application with CUDA execution provider... +python run.py --execution-provider cuda %* diff --git a/run-directml.bat b/run-directml.bat index 038e958..90a4b18 100644 --- a/run-directml.bat +++ b/run-directml.bat @@ -1 +1,16 @@ -python run.py --execution-provider dml +@echo off +set VENV_DIR=.venv + +:: Check if virtual environment exists +if not exist "%VENV_DIR%\Scripts\activate.bat" ( + echo Virtual environment '%VENV_DIR%' not found. + echo Please run setup_windows.bat first. + pause + exit /b 1 +) + +echo Activating virtual environment... +call "%VENV_DIR%\Scripts\activate.bat" + +echo Starting the application with DirectML execution provider... +python run.py --execution-provider dml %* diff --git a/run_windows.bat b/run_windows.bat new file mode 100644 index 0000000..3894226 --- /dev/null +++ b/run_windows.bat @@ -0,0 +1,20 @@ +@echo off +set VENV_DIR=.venv + +:: Check if virtual environment exists +if not exist "%VENV_DIR%\Scripts\activate.bat" ( + echo Virtual environment '%VENV_DIR%' not found. + echo Please run setup_windows.bat first to create the environment and install dependencies. + pause + exit /b 1 +) + +echo Activating virtual environment... +call "%VENV_DIR%\Scripts\activate.bat" + +echo Starting the application with CPU execution provider... +:: Passes all arguments passed to this script to run.py +python run.py --execution-provider cpu %* + +:: Optional: Deactivate after script finishes +:: call deactivate diff --git a/setup_windows.bat b/setup_windows.bat new file mode 100644 index 0000000..4a80b49 --- /dev/null +++ b/setup_windows.bat @@ -0,0 +1,79 @@ +@echo off +echo Starting Windows setup... + +:: 1. Check for Python +echo Checking for Python... +python --version >nul 2>&1 +if errorlevel 1 ( + echo Python could not be found in your PATH. + echo Please install Python 3 (3.10 or higher recommended) and ensure it's added to your PATH. + echo You can download Python from https://www.python.org/downloads/ + pause + exit /b 1 +) + +:: Optional: Check Python version (e.g., >= 3.9 or >=3.10). +:: This is a bit more complex in pure batch. For now, rely on user having a modern Python 3. +:: The README will recommend 3.10. +echo Found Python: +python --version + +:: 2. Check for ffmpeg (informational) +echo Checking for ffmpeg... +ffmpeg -version >nul 2>&1 +if errorlevel 1 ( + echo WARNING: ffmpeg could not be found in your PATH. This program requires ffmpeg for video processing. + echo Please download ffmpeg from https://ffmpeg.org/download.html and add it to your system's PATH. + echo (The README.md contains a link for a potentially easier ffmpeg install method using a PowerShell command) + echo Continuing with setup, but video processing might fail later. + pause +) else ( + echo ffmpeg found. +) + +:: 3. Define virtual environment directory +set VENV_DIR=.venv + +:: 4. Create virtual environment +if exist "%VENV_DIR%\Scripts\activate.bat" ( + echo Virtual environment '%VENV_DIR%' already exists. Skipping creation. +) else ( + echo Creating virtual environment in '%VENV_DIR%'... + python -m venv "%VENV_DIR%" + if errorlevel 1 ( + echo Failed to create virtual environment. Please check your Python installation. + pause + exit /b 1 + ) +) + +:: 5. Activate virtual environment (for this script's session) +echo Activating virtual environment... +call "%VENV_DIR%\Scripts\activate.bat" + +:: 6. Upgrade pip +echo Upgrading pip... +python -m pip install --upgrade pip + +:: 7. Install requirements +echo Installing requirements from requirements.txt... +if exist "requirements.txt" ( + python -m pip install -r requirements.txt +) else ( + echo ERROR: requirements.txt not found. Cannot install dependencies. + pause + exit /b 1 +) + +echo. +echo Setup complete! +echo. +echo To activate the virtual environment in your command prompt, run: +echo %VENV_DIR%\Scripts\activate.bat +echo. +echo After activating, you can run the application using: +echo python run.py [arguments] +echo Or use one of the run-*.bat scripts (e.g., run-cuda.bat, run_windows.bat). +echo. +pause +exit /b 0