Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows installation ? #15

Open
BenDes21 opened this issue Jan 21, 2025 · 5 comments
Open

Windows installation ? #15

BenDes21 opened this issue Jan 21, 2025 · 5 comments

Comments

@BenDes21
Copy link

is it possible to use the script on windows ?

@D-Ogi
Copy link
Owner

D-Ogi commented Jan 25, 2025

I don't have access to Windows environment at the moment. Could you try (on your own risk) to run the following batch script?

Using it should be simple. Just create a text file in your local copy of this repository (git clone https://github.com/D-Ogi/WatermarkRemover-AI ), paste the content from block below, save it a run.bat and double click it.

As linux startup script it parses Command-Line Arguments like --activate, --reinstall, --current-dir, and --help.

setlocal EnableExtensions EnableDelayedExpansion

:: ============================================
:: Configuration
:: ============================================
set "ENV_NAME=py312aiwatermark"
set "ENV_FILE=environment.yml"
set "MINICONDA_DOWNLOAD_URL=https://repo.anaconda.com/miniconda/Miniconda3-py312_24.11.1-0-Windows-x86_64.exe"
set "MINICONDA_CHECKSUM=be382fc02742c734fd3c399c5e5d322bc9b43292117827ab9aa6f7446351e45c"

:: Default values
set "INSTALL_DIR="
set "USE_DEFAULT_DIR=true"
set "FORCE_REINSTALL=false"
set "ACTIVATE_ONLY=false"
set "SCRIPT_ARGS="

:: ============================================
:: Functions
:: ============================================

:: Function to display usage
:usage
echo Usage: %~nx0 [options] -- [script arguments]
echo.
echo Options:
echo   --activate                Activate the Conda environment and provide instructions to deactivate it.
echo   --reinstall               Reinstall the Conda environment.
echo   --current-dir             Use the current directory as the root for the Conda environment.
echo   --help                    Show this help message.
echo.
echo Script Arguments:
echo   Any arguments after -- will be passed directly to remwm.py.
goto end

:: Function to download Miniconda
:download_miniconda
echo Downloading Miniconda from %MINICONDA_DOWNLOAD_URL% to "%INSTALL_DIR%\miniconda_installer.exe"...
powershell -Command "Invoke-WebRequest -Uri '%MINICONDA_DOWNLOAD_URL%' -OutFile '%INSTALL_DIR%\miniconda_installer.exe'" || (
    echo Failed to download Miniconda.
    goto end
)
goto :verify_checksum

:: Function to verify Miniconda checksum
:verify_checksum
echo Verifying checksum for Miniconda installer...
CertUtil -hashfile "%INSTALL_DIR%\miniconda_installer.exe" SHA256 | findstr /I "%MINICONDA_CHECKSUM%" >nul
if %ERRORLEVEL% EQU 0 (
    echo Checksum verification passed.
) else (
    echo Checksum verification failed.
    del "%INSTALL_DIR%\miniconda_installer.exe"
    goto end
)
goto :install_miniconda

:: Function to install Miniconda silently
:install_miniconda
echo Installing Miniconda to "%CONDA_ROOT_PREFIX%"...
"%INSTALL_DIR%\miniconda_installer.exe" /InstallationType=JustMe /AddToPath=0 /RegisterPython=0 /S /D=%CONDA_ROOT_PREFIX%
if %ERRORLEVEL% NEQ 0 (
    echo Miniconda installation failed.
    del "%INSTALL_DIR%\miniconda_installer.exe"
    goto end
)
del "%INSTALL_DIR%\miniconda_installer.exe"
goto :check_conda

:: Function to check if Conda is installed
:check_conda
where conda >nul 2>&1
if %ERRORLEVEL% NEQ 0 (
    echo Conda not found. Installing Miniconda...
    set "CONDA_ROOT_PREFIX=%INSTALL_DIR%\conda"
    mkdir "%CONDA_ROOT_PREFIX%" 2>nul
    call :download_miniconda
) else (
    echo Conda is already installed.
)
goto :configure_conda

:: Function to configure Conda environment paths
:configure_conda
if "%USE_DEFAULT_DIR%"=="false" (
    set "CONDA_ENVS_PATH=%INSTALL_DIR%\conda_envs"
    set "CONDA_PKGS_DIRS=%INSTALL_DIR%\conda_pkgs"
    echo Using current directory as the root for Conda environments: %CONDA_ENVS_PATH%
) else (
    :: Attempt to find existing installation
    call :find_existing_install_dir
)
goto :manage_environment

:: Function to find existing Conda environment directory
:find_existing_install_dir
set "EXISTING_DIR="
for /f "tokens=1" %%i in ('conda env list ^| findstr /R "^%ENV_NAME% *"') do (
    set "EXISTING_DIR=%CD%\conda_envs"
)
if defined EXISTING_DIR (
    set "CONDA_ENVS_PATH=%EXISTING_DIR%"
    set "CONDA_PKGS_DIRS=%EXISTING_DIR%\pkgs"
    echo Detected existing installation in: %CONDA_ENVS_PATH%
) else (
    echo Using default Conda directory.
)
goto :eof

:: Function to manage the Conda environment
:manage_environment
:: Initialize Conda for the script
call conda init bat >nul 2>&1

:: Refresh the environment
call conda deactivate >nul 2>&1
call conda activate base >nul 2>&1

:: Check if the environment exists
conda env list | findstr /R "^%ENV_NAME% *" >nul
if %ERRORLEVEL% EQU 0 (
    if "%FORCE_REINSTALL%"=="true" (
        echo Reinstalling environment '%ENV_NAME%'...
        call conda env remove -n "%ENV_NAME%" -y
        set "ENV_EXISTS=false"
    ) else (
        echo Environment '%ENV_NAME%' already exists. Activating it...
        call conda activate "%ENV_NAME%"
        set "ENV_EXISTS=true"
    )
) else (
    set "ENV_EXISTS=false"
)

if "%ENV_EXISTS%"=="false" (
    echo Creating Conda environment '%ENV_NAME%' from '%ENV_FILE%'...
    call conda env create -f "%ENV_FILE%" || (
        echo Failed to create the Conda environment.
        goto end
    )
    call conda activate "%ENV_NAME%"
)

if "%ACTIVATE_ONLY%"=="true" (
    echo Environment '%ENV_NAME%' activated. To deactivate, run 'conda deactivate'.
    goto end
)

:: ============================================
:: Install Required Pip Packages
:: ============================================
echo Ensuring required Python packages are installed...
call pip install --upgrade pip >nul 2>&1

:: List of required packages
set "REQUIRED_PACKAGES=PyQt6 transformers iopaint opencv-python-headless"

for %%p in (%REQUIRED_PACKAGES%) do (
    pip show %%p >nul 2>&1
    if %ERRORLEVEL% NEQ 0 (
        echo Installing %%p...
        call pip install %%p
    ) else (
        echo Package %%p is already installed.
    )
)

:: ============================================
:: Run remwm.py with Arguments
:: ============================================
echo Running remwm.py with provided arguments...
python remwm.py %SCRIPT_ARGS%

goto end

:: ============================================
:: Parse Command-Line Arguments
:: ============================================
:parse_args
:loop
if "%~1"=="" goto after_parse

if "%~1"=="--activate" (
    set "ACTIVATE_ONLY=true"
    shift
    goto loop
)

if "%~1"=="--reinstall" (
    set "FORCE_REINSTALL=true"
    shift
    goto loop
)

if "%~1"=="--current-dir" (
    set "USE_DEFAULT_DIR=false"
    set "INSTALL_DIR=%CD%"
    shift
    goto loop
)

if "%~1"=="--help" (
    call :usage
)

if "%~1"=="--" (
    shift
    set "SCRIPT_ARGS=%*"
    goto after_parse
)

echo Unknown option: %~1
call :usage

:after_parse
goto :check_conda

:: ============================================
:: End of Script
:: ============================================
:end
endlocal
exit /b 0

@BenDes21
Copy link
Author

I don't have access to Windows environment at the moment. Could you try (on your own risk) to run the following batch script?

Using it should be simple. Just create a text file in your local copy of this repository (git clone https://github.com/D-Ogi/WatermarkRemover-AI ), paste the content from block below, save it a run.bat and double click it.

As linux startup script it parses Command-Line Arguments like --activate, --reinstall, --current-dir, and --help.

setlocal EnableExtensions EnableDelayedExpansion

:: ============================================
:: Configuration
:: ============================================
set "ENV_NAME=py312aiwatermark"
set "ENV_FILE=environment.yml"
set "MINICONDA_DOWNLOAD_URL=https://repo.anaconda.com/miniconda/Miniconda3-py312_24.11.1-0-Windows-x86_64.exe"
set "MINICONDA_CHECKSUM=be382fc02742c734fd3c399c5e5d322bc9b43292117827ab9aa6f7446351e45c"

:: Default values
set "INSTALL_DIR="
set "USE_DEFAULT_DIR=true"
set "FORCE_REINSTALL=false"
set "ACTIVATE_ONLY=false"
set "SCRIPT_ARGS="

:: ============================================
:: Functions
:: ============================================

:: Function to display usage
:usage
echo Usage: %~nx0 [options] -- [script arguments]
echo.
echo Options:
echo   --activate                Activate the Conda environment and provide instructions to deactivate it.
echo   --reinstall               Reinstall the Conda environment.
echo   --current-dir             Use the current directory as the root for the Conda environment.
echo   --help                    Show this help message.
echo.
echo Script Arguments:
echo   Any arguments after -- will be passed directly to remwm.py.
goto end

:: Function to download Miniconda
:download_miniconda
echo Downloading Miniconda from %MINICONDA_DOWNLOAD_URL% to "%INSTALL_DIR%\miniconda_installer.exe"...
powershell -Command "Invoke-WebRequest -Uri '%MINICONDA_DOWNLOAD_URL%' -OutFile '%INSTALL_DIR%\miniconda_installer.exe'" || (
    echo Failed to download Miniconda.
    goto end
)
goto :verify_checksum

:: Function to verify Miniconda checksum
:verify_checksum
echo Verifying checksum for Miniconda installer...
CertUtil -hashfile "%INSTALL_DIR%\miniconda_installer.exe" SHA256 | findstr /I "%MINICONDA_CHECKSUM%" >nul
if %ERRORLEVEL% EQU 0 (
    echo Checksum verification passed.
) else (
    echo Checksum verification failed.
    del "%INSTALL_DIR%\miniconda_installer.exe"
    goto end
)
goto :install_miniconda

:: Function to install Miniconda silently
:install_miniconda
echo Installing Miniconda to "%CONDA_ROOT_PREFIX%"...
"%INSTALL_DIR%\miniconda_installer.exe" /InstallationType=JustMe /AddToPath=0 /RegisterPython=0 /S /D=%CONDA_ROOT_PREFIX%
if %ERRORLEVEL% NEQ 0 (
    echo Miniconda installation failed.
    del "%INSTALL_DIR%\miniconda_installer.exe"
    goto end
)
del "%INSTALL_DIR%\miniconda_installer.exe"
goto :check_conda

:: Function to check if Conda is installed
:check_conda
where conda >nul 2>&1
if %ERRORLEVEL% NEQ 0 (
    echo Conda not found. Installing Miniconda...
    set "CONDA_ROOT_PREFIX=%INSTALL_DIR%\conda"
    mkdir "%CONDA_ROOT_PREFIX%" 2>nul
    call :download_miniconda
) else (
    echo Conda is already installed.
)
goto :configure_conda

:: Function to configure Conda environment paths
:configure_conda
if "%USE_DEFAULT_DIR%"=="false" (
    set "CONDA_ENVS_PATH=%INSTALL_DIR%\conda_envs"
    set "CONDA_PKGS_DIRS=%INSTALL_DIR%\conda_pkgs"
    echo Using current directory as the root for Conda environments: %CONDA_ENVS_PATH%
) else (
    :: Attempt to find existing installation
    call :find_existing_install_dir
)
goto :manage_environment

:: Function to find existing Conda environment directory
:find_existing_install_dir
set "EXISTING_DIR="
for /f "tokens=1" %%i in ('conda env list ^| findstr /R "^%ENV_NAME% *"') do (
    set "EXISTING_DIR=%CD%\conda_envs"
)
if defined EXISTING_DIR (
    set "CONDA_ENVS_PATH=%EXISTING_DIR%"
    set "CONDA_PKGS_DIRS=%EXISTING_DIR%\pkgs"
    echo Detected existing installation in: %CONDA_ENVS_PATH%
) else (
    echo Using default Conda directory.
)
goto :eof

:: Function to manage the Conda environment
:manage_environment
:: Initialize Conda for the script
call conda init bat >nul 2>&1

:: Refresh the environment
call conda deactivate >nul 2>&1
call conda activate base >nul 2>&1

:: Check if the environment exists
conda env list | findstr /R "^%ENV_NAME% *" >nul
if %ERRORLEVEL% EQU 0 (
    if "%FORCE_REINSTALL%"=="true" (
        echo Reinstalling environment '%ENV_NAME%'...
        call conda env remove -n "%ENV_NAME%" -y
        set "ENV_EXISTS=false"
    ) else (
        echo Environment '%ENV_NAME%' already exists. Activating it...
        call conda activate "%ENV_NAME%"
        set "ENV_EXISTS=true"
    )
) else (
    set "ENV_EXISTS=false"
)

if "%ENV_EXISTS%"=="false" (
    echo Creating Conda environment '%ENV_NAME%' from '%ENV_FILE%'...
    call conda env create -f "%ENV_FILE%" || (
        echo Failed to create the Conda environment.
        goto end
    )
    call conda activate "%ENV_NAME%"
)

if "%ACTIVATE_ONLY%"=="true" (
    echo Environment '%ENV_NAME%' activated. To deactivate, run 'conda deactivate'.
    goto end
)

:: ============================================
:: Install Required Pip Packages
:: ============================================
echo Ensuring required Python packages are installed...
call pip install --upgrade pip >nul 2>&1

:: List of required packages
set "REQUIRED_PACKAGES=PyQt6 transformers iopaint opencv-python-headless"

for %%p in (%REQUIRED_PACKAGES%) do (
    pip show %%p >nul 2>&1
    if %ERRORLEVEL% NEQ 0 (
        echo Installing %%p...
        call pip install %%p
    ) else (
        echo Package %%p is already installed.
    )
)

:: ============================================
:: Run remwm.py with Arguments
:: ============================================
echo Running remwm.py with provided arguments...
python remwm.py %SCRIPT_ARGS%

goto end

:: ============================================
:: Parse Command-Line Arguments
:: ============================================
:parse_args
:loop
if "%~1"=="" goto after_parse

if "%~1"=="--activate" (
    set "ACTIVATE_ONLY=true"
    shift
    goto loop
)

if "%~1"=="--reinstall" (
    set "FORCE_REINSTALL=true"
    shift
    goto loop
)

if "%~1"=="--current-dir" (
    set "USE_DEFAULT_DIR=false"
    set "INSTALL_DIR=%CD%"
    shift
    goto loop
)

if "%~1"=="--help" (
    call :usage
)

if "%~1"=="--" (
    shift
    set "SCRIPT_ARGS=%*"
    goto after_parse
)

echo Unknown option: %~1
call :usage

:after_parse
goto :check_conda

:: ============================================
:: End of Script
:: ============================================
:end
endlocal
exit /b 0

Hi there, thanks for the answer, Im getting this

Image

Im not sure how about what to do after

@BenDes21
Copy link
Author

BenDes21 commented Feb 5, 2025

any news ?

@D-Ogi
Copy link
Owner

D-Ogi commented Feb 7, 2025

I don't have access to Windows machine at the moment, so I cannot fix it. You may try to ask o1/o3-mini/deepseek to rewrite the linux sh file into Windows one - as a batch file or in Powershell.

@BenDes21
Copy link
Author

BenDes21 commented Feb 8, 2025

I don't have access to Windows machine at the moment, so I cannot fix it. You may try to ask o1/o3-mini/deepseek to rewrite the linux sh file into Windows one - as a batch file or in Powershell.

Hi there, yep I tried but unfortunately it's seems to break the script ( the GUI not working or the script not delete completely the watermark )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants