|
@echo off |
|
setlocal enabledelayedexpansion |
|
|
|
:: Set paths |
|
set "INSTALL_DIR=%~dp0" |
|
set "PYTHON_DIR=%INSTALL_DIR%python_embedded" |
|
set "VENV_DIR=%INSTALL_DIR%venv" |
|
set "GIT_DIR=%INSTALL_DIR%PortableGit" |
|
set "G4F_DIR=%INSTALL_DIR%gpt4free" |
|
set "PYTHON_URL=https://www.python.org/ftp/python/3.11.8/python-3.11.8-embed-amd64.zip" |
|
set "GET_PIP_URL=https://bootstrap.pypa.io/get-pip.py" |
|
set "GIT_URL=https://github.com/git-for-windows/git/releases/download/v2.44.0.windows.1/PortableGit-2.44.0-64-bit.7z.exe" |
|
|
|
:: Setup local temp directory |
|
set "TEMP=%INSTALL_DIR%temp" |
|
set "TMP=%INSTALL_DIR%temp" |
|
mkdir "%TEMP%" 2>nul |
|
|
|
echo ====================================================== |
|
echo GPT4Free Portable Installation |
|
echo by Nerual Dreming |
|
echo ====================================================== |
|
echo. |
|
echo Installation directory: %INSTALL_DIR% |
|
echo. |
|
|
|
:: Clean old installation if exists |
|
if exist "%VENV_DIR%" ( |
|
echo Cleaning old virtual environment... |
|
rmdir /s /q "%VENV_DIR%" |
|
) |
|
|
|
:: Download and install portable Git if not exists |
|
if not exist "%GIT_DIR%" ( |
|
echo Downloading portable Git... |
|
powershell -Command "(New-Object Net.WebClient).DownloadFile('%GIT_URL%', '%INSTALL_DIR%PortableGit.exe')" |
|
echo Extracting Git... |
|
"%INSTALL_DIR%PortableGit.exe" -y -gm2 -nr -o"%GIT_DIR%" |
|
del "%INSTALL_DIR%PortableGit.exe" |
|
) |
|
|
|
:: Add Git to PATH temporarily |
|
set "PATH=%GIT_DIR%\bin;%PATH%" |
|
|
|
:: Download and extract Python if not exists |
|
if not exist "%PYTHON_DIR%" ( |
|
echo Downloading Python... |
|
mkdir "%PYTHON_DIR%" |
|
powershell -Command "(New-Object Net.WebClient).DownloadFile('%PYTHON_URL%', '%INSTALL_DIR%python.zip')" |
|
powershell -Command "Expand-Archive '%INSTALL_DIR%python.zip' -DestinationPath '%PYTHON_DIR%'" |
|
del "%INSTALL_DIR%python.zip" |
|
|
|
:: Configure python to use pip |
|
echo Configuring Python... |
|
powershell -Command "(Get-Content '%PYTHON_DIR%\python311._pth') -replace '#import site', 'import site' | Set-Content '%PYTHON_DIR%\python311._pth'" |
|
|
|
:: Install pip |
|
echo Installing pip... |
|
powershell -Command "(New-Object Net.WebClient).DownloadFile('%GET_PIP_URL%', '%PYTHON_DIR%\get-pip.py')" |
|
"%PYTHON_DIR%\python.exe" "%PYTHON_DIR%\get-pip.py" --no-warn-script-location |
|
del "%PYTHON_DIR%\get-pip.py" |
|
) |
|
|
|
:: Install virtualenv in the embedded Python |
|
echo Installing virtualenv... |
|
"%PYTHON_DIR%\python.exe" -m pip install --no-cache-dir virtualenv |
|
|
|
:: Create virtual environment |
|
echo Creating virtual environment... |
|
"%PYTHON_DIR%\python.exe" -m virtualenv --no-download "%VENV_DIR%" |
|
|
|
:: Clone the gpt4free repository if not exists |
|
if not exist "%G4F_DIR%" ( |
|
echo Cloning gpt4free repository... |
|
"%GIT_DIR%\bin\git.exe" clone https://github.com/xtekky/gpt4free.git "%G4F_DIR%" |
|
) |
|
|
|
:: Configure pip to use local directories |
|
set "PIP_CACHE_DIR=%INSTALL_DIR%pip_cache" |
|
set "PYTHONUSERBASE=%INSTALL_DIR%python_user_base" |
|
|
|
:: Activate virtual environment |
|
call "%VENV_DIR%\Scripts\activate.bat" |
|
|
|
:: Install dependencies |
|
echo Installing dependencies... |
|
python -m pip install --no-cache-dir --upgrade pip |
|
python -m pip install --no-cache-dir -r "%G4F_DIR%\requirements.txt" |
|
python -m pip install --no-cache-dir -e "%G4F_DIR%" |
|
|
|
:: Create directories for data storage |
|
mkdir "%G4F_DIR%\generated_images" 2>nul |
|
mkdir "%G4F_DIR%\har_and_cookies" 2>nul |
|
|
|
:: Create launcher scripts |
|
echo Creating launcher scripts... |
|
( |
|
echo @echo off |
|
echo setlocal enabledelayedexpansion |
|
echo cd /d "%%~dp0" |
|
echo echo Starting gpt4free server... |
|
echo set "PATH=%%~dp0venv\Scripts;%%PATH%%" |
|
echo set "TEMP=%%~dp0temp" |
|
echo set "TMP=%%~dp0temp" |
|
echo if not exist "%%TEMP%%" mkdir "%%TEMP%%" |
|
echo call "venv\Scripts\activate.bat" |
|
echo cd gpt4free |
|
echo python -m g4f --port 8080 --debug |
|
echo pause |
|
) > "%INSTALL_DIR%start_server.bat" |
|
|
|
( |
|
echo @echo off |
|
echo setlocal enabledelayedexpansion |
|
echo cd /d "%%~dp0" |
|
echo start cmd /k "start_server.bat" |
|
echo echo Waiting for server to start... |
|
echo timeout /t 3 /nobreak |
|
echo echo Opening browser... |
|
echo start http://127.0.0.1:8080/chat/ |
|
) > "%INSTALL_DIR%start_gpt4free.bat" |
|
|
|
:: Create updater script |
|
echo Creating updater script... |
|
( |
|
echo @echo off |
|
echo setlocal enabledelayedexpansion |
|
echo. |
|
echo cd /d "%%~dp0" |
|
echo. |
|
echo set "INSTALL_DIR=%%~dp0" |
|
echo set "G4F_DIR=%%INSTALL_DIR%%gpt4free" |
|
echo set "VENV_DIR=%%INSTALL_DIR%%venv" |
|
echo set "TEMP=%%INSTALL_DIR%%temp" |
|
echo set "TMP=%%INSTALL_DIR%%temp" |
|
echo. |
|
echo echo ====================================================== |
|
echo echo GPT4Free Updater |
|
echo echo by Nerual Dreming |
|
echo echo ====================================================== |
|
echo echo. |
|
echo. |
|
echo :: Check if installation exists |
|
echo if not exist "%%G4F_DIR%%" ( |
|
echo echo Error: gpt4free not found in %%G4F_DIR%% |
|
echo echo Please run install_gpt4free.bat first |
|
echo pause |
|
echo exit /b 1 |
|
echo ^) |
|
echo. |
|
echo if not exist "%%VENV_DIR%%" ( |
|
echo echo Error: Virtual environment not found in %%VENV_DIR%% |
|
echo echo Please run install_gpt4free.bat first |
|
echo pause |
|
echo exit /b 1 |
|
echo ^) |
|
echo. |
|
echo :: Activate virtual environment |
|
echo call "%%VENV_DIR%%\Scripts\activate.bat" |
|
echo. |
|
echo :: Update repository |
|
echo echo Updating gpt4free repository... |
|
echo cd "%%G4F_DIR%%" |
|
echo git pull |
|
echo. |
|
echo :: Update dependencies |
|
echo echo Updating dependencies... |
|
echo python -m pip install --no-cache-dir --upgrade pip |
|
echo python -m pip install --no-cache-dir -r requirements.txt |
|
echo python -m pip install --no-cache-dir -e . |
|
echo. |
|
echo echo ============================================= |
|
echo echo Update completed successfully! |
|
echo echo ============================================= |
|
echo. |
|
echo pause |
|
) > "%INSTALL_DIR%update_gpt4free.bat" |
|
|
|
echo ============================================= |
|
echo Installation completed successfully! |
|
echo. |
|
echo To launch gpt4free, run: |
|
echo start_gpt4free.bat |
|
echo. |
|
echo To update gpt4free to the latest version: |
|
echo update_gpt4free.bat |
|
echo ============================================= |
|
|
|
:: Cleanup temp files |
|
rmdir /s /q "%TEMP%" 2>nul |
|
|
|
pause |