Compare commits

..

1 Commits

Author SHA1 Message Date
rehanbgmi ff0608292d
Merge 2e617c9401 into 28109e93bb 2025-05-25 22:37:31 +05:30
9 changed files with 13 additions and 241 deletions

View File

@ -134,57 +134,12 @@ Place these files in the "**models**" folder.
We highly recommend using a `venv` to avoid issues.
**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 Windows:
```bash
python -m venv venv
venv\Scripts\activate
pip install -r requirements.txt
```
For Linux:
```bash
# Ensure you use the installed Python 3.10

View File

@ -1,45 +0,0 @@
{
"Source x Target Mapper": "Сопоставитель Источник x Цель",
"select a source image": "выберите исходное изображение",
"Preview": "Предпросмотр",
"select a target image or video": "выберите целевое изображение или видео",
"save image output file": "сохранить выходной файл изображения",
"save video output file": "сохранить выходной файл видео",
"select a target image": "выберите целевое изображение",
"source": "источник",
"Select a target": "Выберите целевое изображение",
"Select a face": "Выберите лицо",
"Keep audio": "Сохранить аудио",
"Face Enhancer": "Улучшение лица",
"Many faces": "Несколько лиц",
"Show FPS": "Показать FPS",
"Keep fps": "Сохранить FPS",
"Keep frames": "Сохранить кадры",
"Fix Blueish Cam": "Исправить синеву камеры",
"Mouth Mask": "Маска рта",
"Show Mouth Mask Box": "Показать рамку маски рта",
"Start": "Старт",
"Live": "В реальном времени",
"Destroy": "Остановить",
"Map faces": "Сопоставить лица",
"Processing...": "Обработка...",
"Processing succeed!": "Обработка успешна!",
"Processing ignored!": "Обработка проигнорирована!",
"Failed to start camera": "Не удалось запустить камеру",
"Please complete pop-up or close it.": "Пожалуйста, заполните всплывающее окно или закройте его.",
"Getting unique faces": "Получение уникальных лиц",
"Please select a source image first": "Сначала выберите исходное изображение, пожалуйста",
"No faces found in target": "В целевом изображении не найдено лиц",
"Add": "Добавить",
"Clear": "Очистить",
"Submit": "Отправить",
"Select source image": "Выбрать исходное изображение",
"Select target image": "Выбрать целевое изображение",
"Please provide mapping!": "Пожалуйста, укажите сопоставление!",
"At least 1 source with target is required!": "Требуется хотя бы 1 источник с целью!",
"Face could not be detected in last upload!": "Лицо не обнаружено в последнем загруженном изображении!",
"Select Camera:": "Выберите камеру:",
"All mappings cleared!": "Все сопоставления очищены!",
"Mappings successfully submitted!": "Сопоставления успешно отправлены!",
"Source x Target Mapper is already open.": "Сопоставитель Источник-Цель уже открыт."
}

View File

@ -1,4 +1,4 @@
from typing import Any, List, Optional, Tuple
from typing import Any, List
import cv2
import insightface
import threading
@ -72,8 +72,8 @@ def _prepare_warped_source_material_and_mask(
source_face_obj: Face,
source_frame_full: Frame,
matrix: np.ndarray,
dsize: tuple # Built-in tuple is fine here for parameter type
) -> Tuple[Optional[Frame], Optional[Frame]]:
dsize: tuple
) -> tuple[Frame | None, Frame | None]:
"""
Prepares warped source material (full image) and a combined (face+hair) mask for blending.
Returns (None, None) if essential masks cannot be generated.

View File

@ -1013,6 +1013,7 @@ def create_webcam_preview(camera_index: int):
temp_frame, PREVIEW.winfo_width(), PREVIEW.winfo_height()
)
if not modules.globals.map_faces:
if not modules.globals.map_faces:
# Case 1: map_faces is False - source_face_obj_for_cam and source_frame_full_for_cam are pre-loaded
if source_face_obj_for_cam and source_frame_full_for_cam is not None: # Check if valid after pre-loading

View File

@ -50,17 +50,7 @@ class VideoCapturer:
continue
else:
# Unix-like systems (Linux/Mac) capture method
if platform.system() == "Darwin": # macOS
print("INFO: Attempting to use cv2.CAP_AVFOUNDATION for macOS camera.")
self.cap = cv2.VideoCapture(self.device_index, cv2.CAP_AVFOUNDATION)
if not self.cap or not self.cap.isOpened():
print("WARN: cv2.CAP_AVFOUNDATION failed to open camera. Trying default backend for macOS.")
# Release the failed attempt before trying again
if self.cap:
self.cap.release()
self.cap = cv2.VideoCapture(self.device_index) # Fallback to default
else: # Other Unix-like systems (e.g., Linux)
self.cap = cv2.VideoCapture(self.device_index)
self.cap = cv2.VideoCapture(self.device_index)
if not self.cap or not self.cap.isOpened():
raise RuntimeError("Failed to open camera")

View File

@ -1,16 +1 @@
@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 %*
python run.py --execution-provider cuda

View File

@ -1,16 +1 @@
@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 %*
python run.py --execution-provider dml

View File

@ -1,20 +0,0 @@
@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

View File

@ -1,79 +0,0 @@
@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