@echo off setlocal EnableExtensions DisableDelayedExpansion title AILITH - Hugging Face Uploader set "AILITH_EXIT_CODE=1" set "AILITH_PY_CMD=" set "AILITH_ENV_DIR=" if not exist "%~dp0hf_upload.py" ( echo ERROR: hf_upload.py is missing. echo Extract all uploader files into the same folder, then try again. goto finish ) py -3 -c "import sys; raise SystemExit(0 if sys.version_info >= (3, 10) else 1)" >nul 2>&1 if not errorlevel 1 ( set "AILITH_PY_CMD=py -3" goto scan_args ) python -c "import sys; raise SystemExit(0 if sys.version_info >= (3, 10) else 1)" >nul 2>&1 if not errorlevel 1 ( set "AILITH_PY_CMD=python" goto scan_args ) echo ERROR: Python 3.10 or newer was not found. echo Install Python from https://www.python.org/downloads/windows/ echo Include the Python launcher or add Python to PATH, then reopen this file. goto finish :scan_args rem SHIFT changes numbered arguments, but %%* retains the original arguments. rem Dry runs and help must work without network access or installing packages. if "%~1"=="" goto setup if /I "%~1"=="--dry-run" goto run_base_python if /I "%~1"=="--help" goto run_base_python if /I "%~1"=="-h" goto run_base_python shift /1 goto scan_args :setup if not defined LOCALAPPDATA goto setup_temp set "AILITH_ENV_DIR=%LOCALAPPDATA%\AILITH\hf-uploader" call :prepare_env if not errorlevel 1 goto check_dependency echo Could not prepare the uploader environment in LocalAppData. :setup_temp if not defined TEMP ( echo ERROR: No writable uploader environment could be located. echo Set LOCALAPPDATA or TEMP to a writable folder and try again. goto finish ) set "AILITH_ENV_DIR=%TEMP%\AILITH\hf-uploader" call :prepare_env if not errorlevel 1 goto check_dependency echo ERROR: Could not prepare the isolated Python environment. echo Check available disk space and folder permissions, then try again. goto finish :check_dependency "%AILITH_ENV_DIR%\Scripts\python.exe" -c "import huggingface_hub; from importlib.metadata import version; v=version('huggingface_hub').split('.'); raise SystemExit(0 if v[0] in ('1', '2') else 1)" >nul 2>&1 if not errorlevel 1 goto run_uploader echo Installing the Hugging Face upload dependency into the uploader environment... "%AILITH_ENV_DIR%\Scripts\python.exe" -m pip --version >nul 2>&1 if not errorlevel 1 goto install_dependency "%AILITH_ENV_DIR%\Scripts\python.exe" -m ensurepip --upgrade if errorlevel 1 ( echo ERROR: pip could not be prepared in the uploader environment. goto finish ) :install_dependency "%AILITH_ENV_DIR%\Scripts\python.exe" -m pip --disable-pip-version-check install "huggingface_hub>=1.0,<3" if errorlevel 1 ( echo ERROR: The dependency could not be installed. echo Check your Internet connection and retry. No upload has started. goto finish ) :run_uploader "%AILITH_ENV_DIR%\Scripts\python.exe" "%~dp0hf_upload.py" %* set "AILITH_EXIT_CODE=%ERRORLEVEL%" goto finish :run_base_python %AILITH_PY_CMD% "%~dp0hf_upload.py" %* set "AILITH_EXIT_CODE=%ERRORLEVEL%" goto finish :prepare_env if not exist "%AILITH_ENV_DIR%\Scripts\python.exe" goto create_env "%AILITH_ENV_DIR%\Scripts\python.exe" -c "import sys; raise SystemExit(0 if sys.version_info >= (3, 10) and sys.prefix != sys.base_prefix else 1)" >nul 2>&1 if not errorlevel 1 exit /b 0 :create_env echo Preparing the isolated Python environment... %AILITH_PY_CMD% -m venv "%AILITH_ENV_DIR%" if errorlevel 1 exit /b 1 "%AILITH_ENV_DIR%\Scripts\python.exe" -c "import sys; raise SystemExit(0 if sys.version_info >= (3, 10) and sys.prefix != sys.base_prefix else 1)" >nul 2>&1 exit /b %ERRORLEVEL% :finish echo. if not "%AILITH_EXIT_CODE%"=="0" echo Uploader stopped with exit code %AILITH_EXIT_CODE%. pause endlocal & exit /b %AILITH_EXIT_CODE%