Compare commits

..

8 Commits

Author SHA1 Message Date
rehanbgmi 963b8d84e0
Merge 5f2e54552c into ab8a1c82c1 2025-05-26 02:34:57 +05:30
KRSHH ab8a1c82c1
Merge pull request #1310 from Jocund96/main
Add Russian locale file: ru.json
2025-05-26 02:34:03 +05:30
Jasurbek Odilov e1842ae0ba
Merge pull request #1 from Jocund96/Jocund96-patch-1
Add locale Russian
2025-05-25 21:28:57 +02:00
Jasurbek Odilov 989106e914
Add files via upload 2025-05-25 21:28:07 +02:00
google-labs-jules[bot] 5f2e54552c 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.
2025-05-25 18:42:44 +00:00
google-labs-jules[bot] d2794038f7 Okay, I've made a change to prioritize AVFoundation for macOS camera access.
I modified `modules/video_capture.py` so that it will explicitly try using `cv2.CAP_AVFOUNDATION` when initializing `cv2.VideoCapture` on macOS. If AVFoundation fails to open the camera, it will then fall back to the default OpenCV backend.

This adjustment should improve camera compatibility and stability on macOS, especially in situations where the default backend might not be working as expected.
2025-05-25 18:26:15 +00:00
google-labs-jules[bot] 521cad145d fix: Update type hints for Python 3.9 compatibility
Replaces Python 3.10+ type hint syntax (e.g., Frame | None)
with Python 3.9 compatible syntax (e.g., Optional[Frame])
in modules/processors/frame/face_swapper.py.

This resolves a TypeError encountered when running on Python 3.9.
Specifically, the return type of _prepare_warped_source_material_and_mask
was updated.
2025-05-25 18:10:43 +00:00
google-labs-jules[bot] 3d8af5180d fix: Correct IndentationError in modules/ui.py
Removes a duplicated 'if not modules.globals.map_faces:' line within the create_webcam_preview function. This error was causing a syntax issue and preventing the application from running correctly, particularly in webcam mode.
2025-05-25 17:57:58 +00:00
9 changed files with 241 additions and 13 deletions

View File

@ -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

45
locales/ru.json 100644
View File

@ -0,0 +1,45 @@
{
"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
from typing import Any, List, Optional, Tuple
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
) -> tuple[Frame | None, Frame | None]:
dsize: tuple # Built-in tuple is fine here for parameter type
) -> Tuple[Optional[Frame], Optional[Frame]]:
"""
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,7 +1013,6 @@ 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,6 +50,16 @@ 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)
if not self.cap or not self.cap.isOpened():

View File

@ -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 %*

View File

@ -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 %*

20
run_windows.bat 100644
View File

@ -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

79
setup_windows.bat 100644
View File

@ -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