Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Batch windows script to download models from Hugging Face using aria2c (FASTER! than GIT or wget ... supports RESUME! )
- This is a batch script that can download files from Hugging Face models using the aria2c command-line tool. It takes a URL which you get by copying the download link of the model as an argument and the script extracts the file name from the URL automatically. It then uses the aria2c tool to download the file to a specified directory with the extracted file name. It also checks the exit code of the aria2c tool and displays a message indicating the success or failure of the download.
- ## How to use the script
- - Download and install the aria2c tool from the [official website] or use the [web search results] I found for you.
- - Save the script as a .bat file in the same directory as the aria2c.exe file or modify the script to specify the aria2c executable path.
- - Run the script from the command prompt and provide the URL of the file you want to download from Hugging Face models as an argument.
- -without target directory given it will download to the current scripts dir.
- For example:
- ```batch
- mydownloader.bat https://huggingface.co/h94/IP-Adapter/resolve/main/sdxl_models/ip-adapter-plus_sdxl_vit-h.safetensors?download g:\models
- ```
- The script will download the file to the download directory and save it with the extracted file name. For example:
- D:\ML_MODELS\ip-adapter-plus_sdxl_vit-h.safetensors
- CODE to go in the cmd or bat file:
- @echo off
- rem This script takes a URL as an argument and downloads the file using aria2c
- rem Usage: mydownloader.bat https://huggingface.co/h94/IP-Adapter/resolve/main/sdxl_models/ip-adapter-plus_sdxl_vit-h.safetensors?download
- rem This will get the last parameter in %last%
- for %%a in (%*) do set last=%%a
- rem Check if the argument is provided
- if "%1"=="" (
- echo No URL provided. Please provide a valid URL as an argument.
- exit /b 1
- )
- rem Extract the file name from the URL
- for /f "tokens=7 delims=/" %%a in ("%1") do (
- set file_name=%%a
- )
- for /f "tokens=1 delims=?" %%a in ("%file_name%") do (
- set file_name=%%a
- )
- rem Check if the last string contains \
- echo %last%|findstr "\\" >nul
- if errorlevel 1 (
- rem No \ found, set download path as current directory
- set download_dir=%cd%
- echo !
- echo %file_name% will be downloaded to the current directory
- ) else (
- rem \ found, set download path as last string
- set download_dir=%last%
- echo !
- echo %file_name% will be downloaded to %last%
- )
- rem Set the aria2c executable path
- set aria2c_path=aria2c.exe
- rem Download the file using aria2c
- %aria2c_path% -c -V -x 10 -d "%download_dir%" -o "%file_name%" "%1"
- rem Check the exit code of aria2c
- if %errorlevel% equ 0 (
- echo Download completed successfully.
- ) else (
- echo Download failed with error code %errorlevel%.
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement