Skip to content

Instantly share code, notes, and snippets.

@ErickCHIN000
Created February 3, 2025 03:11
Show Gist options
  • Save ErickCHIN000/547f655e99841165f725a1751e7459d5 to your computer and use it in GitHub Desktop.
Save ErickCHIN000/547f655e99841165f725a1751e7459d5 to your computer and use it in GitHub Desktop.
@echo off
setlocal enabledelayedexpansion
:: Define project details
set "REPO_OWNER=ack00gar"
set "REPO_NAME=VR-Funscript-AI-Generator"
set "BRANCH=main"
set "REPO_URL=https://github.com/%REPO_OWNER%/%REPO_NAME%.git"
set "ZIP_URL=https://github.com/%REPO_OWNER%/%REPO_NAME%/archive/refs/heads/%BRANCH%.zip"
set "OUTPUT_FILE=%REPO_NAME%.zip"
set "EXTRACT_DIR=%REPO_NAME%-%BRANCH%"
set "PYTHON_SCRIPT=FSGenerator.py"
set "TEMP_REQUIREMENTS=requirements_without_torch.txt"
set "MODEL_DIR=models"
set "MODEL_FILE=k00gar-11n-RGB-200ep-best.pt"
set "MODEL_URL=https://gofile.io/d/vbfanE"
:: Step 1: Check if the repository is already downloaded
if exist "%REPO_NAME%" (
echo Repository already exists. Skipping download and extraction.
cd "%REPO_NAME%"
) else (
echo Repository not found. Attempting to download...
:: Try Git first
where git >nul 2>nul
if %errorlevel% equ 0 (
echo Git is installed. Cloning repository...
git clone "%REPO_URL%"
cd "%REPO_NAME%"
) else (
echo Git not found. Falling back to ZIP download...
where curl >nul 2>nul
if %errorlevel% equ 0 (
echo Using curl to download ZIP...
curl -L -o "%OUTPUT_FILE%" "%ZIP_URL%"
) else (
echo curl not found. Trying bitsadmin...
bitsadmin /transfer "DownloadRepo" "%ZIP_URL%" "%cd%\%OUTPUT_FILE%"
)
:: Verify download
if not exist "%OUTPUT_FILE%" (
echo Download failed. Please check your internet connection.
pause
exit /b 1
)
:: Extract the ZIP
echo Extracting repository...
powershell -Command "Expand-Archive -Path '%OUTPUT_FILE%' -DestinationPath '.' -Force"
del "%OUTPUT_FILE%"
cd "%EXTRACT_DIR%"
)
)
:: Step 2: Check if virtual environment exists
if exist "venv\Scripts\activate" (
echo Virtual environment already exists. Skipping setup.
) else (
echo Creating virtual environment...
python -m venv venv
)
:: Step 3: Activate virtual environment
echo Activating virtual environment...
call venv\Scripts\activate
:: Step 4: Create a requirements file without PyTorch packages
if not exist "%TEMP_REQUIREMENTS%" (
echo Removing PyTorch from requirements.txt...
python -c "lines=open('requirements.txt').readlines(); open('%TEMP_REQUIREMENTS%', 'w').writelines([l for l in lines if not l.startswith(('torch', 'torchvision', 'torchaudio'))])"
)
:: Step 5: Check if dependencies (excluding PyTorch) are installed
echo Checking installed dependencies...
for /f %%A in ('python -c "import pkg_resources, sys; required=open('%TEMP_REQUIREMENTS%').read().splitlines(); missing=[pkg for pkg in required if not any(d.project_name.lower() == pkg.split('==')[0].lower() for d in pkg_resources.working_set)]; sys.exit(len(missing))"') do set "MISSING_DEPENDENCIES=%%A"
if "%MISSING_DEPENDENCIES%"=="0" (
echo All dependencies are installed. Skipping package installation.
) else (
echo Installing all dependencies except PyTorch...
pip install --no-cache-dir -r "%TEMP_REQUIREMENTS%"
)
:: Step 6: Detect CUDA Version
set "CUDA_VERSION="
for /f %%A in ('python -c "import subprocess, re; out=subprocess.run(['nvcc', '--version'], capture_output=True, text=True).stdout; match=re.search(r'release (\d+\.\d+)', out); print(match.group(1) if match else '')"') do (
set "CUDA_VERSION=%%A"
)
:: Step 7: Check if correct PyTorch version is installed
set "INSTALLED_TORCH_VERSION="
for /f %%A in ('python -c "import torch; print(torch.version.cuda if torch.cuda.is_available() else 'CPU')"') do (
set "INSTALLED_TORCH_VERSION=%%A"
)
:: If correct CUDA PyTorch is installed, skip reinstallation
if "%INSTALLED_TORCH_VERSION%"=="%CUDA_VERSION%" (
echo Correct PyTorch version for CUDA %CUDA_VERSION% is already installed. Skipping reinstallation.
) else (
echo Installing correct PyTorch for CUDA %CUDA_VERSION%...
pip uninstall -y torch torchvision torchaudio
set "TORCH_URL="
if "%CUDA_VERSION%"=="12.1" set "TORCH_URL=https://download.pytorch.org/whl/cu121"
if "%CUDA_VERSION%"=="12.0" set "TORCH_URL=https://download.pytorch.org/whl/cu120"
if "%CUDA_VERSION%"=="11.8" set "TORCH_URL=https://download.pytorch.org/whl/cu118"
if "%CUDA_VERSION%"=="11.7" set "TORCH_URL=https://download.pytorch.org/whl/cu117"
if defined TORCH_URL (
echo Installing PyTorch for CUDA %CUDA_VERSION%...
pip install torch torchvision torchaudio --index-url "!TORCH_URL!"
) else (
echo No compatible CUDA version detected. Installing PyTorch from requirements.txt...
pip install torch torchvision torchaudio
)
)
echo The program will start after this, please make sure the "Model" folder exists and contains the actual model "k00gar-11n-RGB-200ep-best.pt"
pause
:: Skip downloading model step (until fix is found)
goto StartPy
:: Step 8: Check & Download Model File if Needed
echo Checking for model file...
:: Ensure models directory exists
if not exist "%MODEL_DIR%" (
echo Model directory does not exist. Creating it...
mkdir "%MODEL_DIR%"
)
:: Check if the model file exists
if exist "%MODEL_DIR%\%MODEL_FILE%" (
echo Model file already exists. Skipping download.
) else (
echo Model file not found. Downloading...
:: this will not work as gofile requires their api to be used and im not gonna do that in batch
:: i would suggest hosting the model file somewhere else
:: Try using curl first
where curl >nul 2>nul
if %errorlevel% equ 0 (
echo Using curl to download model...
curl -L -o "%MODEL_DIR%\%MODEL_FILE%" "https://store3.gofile.io/download/web/f46d5103-07d2-4a07-aeae-ba84f5ef2b7a/k00gar-11n-RGB-200ep-best.pt"
) else (
echo curl not found. Trying PowerShell...
powershell -Command "& {Invoke-WebRequest -Uri 'https://store3.gofile.io/download/web/f46d5103-07d2-4a07-aeae-ba84f5ef2b7a/k00gar-11n-RGB-200ep-best.pt' -OutFile '%MODEL_DIR%\%MODEL_FILE%'}"
)
:: Check if the download was successful
if exist "%MODEL_DIR%\%MODEL_FILE%" (
echo Model file downloaded successfully!
) else (
echo Model download failed. Exiting.
pause
exit /b 1
)
)
:StartPy
:: Step 9: Start the final Python script (FSGenerator.py)
echo Setup complete! Running Python script...
python "%PYTHON_SCRIPT%"
:: End
pause
exit /b
@StupidRepo
Copy link

tf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment