File size: 3,871 Bytes
2861100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
@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%