Advertisement
fritolito

Untitled

Dec 2nd, 2023 (edited)
1,808
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Winbatch 2.84 KB | Software | 0 0
  1. # Batch windows script to download models from Hugging Face using aria2c (FASTER! than GIT or wget ... supports RESUME! )
  2.  
  3. 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.
  4.  
  5. ## How to use the script
  6.  
  7. - Download and install the aria2c tool from the [official website] or use the [web search results] I found for you.
  8. - 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.
  9. - 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.
  10. -without target directory given it will download to the current scripts dir.
  11. For example:
  12.  
  13. ```batch
  14. mydownloader.bat https://huggingface.co/h94/IP-Adapter/resolve/main/sdxl_models/ip-adapter-plus_sdxl_vit-h.safetensors?download g:\models
  15. ```
  16. The script will download the file to the download directory and save it with the extracted file name. For example:
  17. D:\ML_MODELS\ip-adapter-plus_sdxl_vit-h.safetensors
  18.  
  19.  
  20. CODE to go in the cmd or bat file:
  21. @echo off
  22. rem This script takes a URL as an argument and downloads the file using aria2c
  23. rem Usage: mydownloader.bat https://huggingface.co/h94/IP-Adapter/resolve/main/sdxl_models/ip-adapter-plus_sdxl_vit-h.safetensors?download
  24.  
  25. rem This will get the last parameter in %last%
  26. for %%a in (%*) do set last=%%a
  27.  
  28. rem Check if the argument is provided
  29. if "%1"=="" (
  30.     echo No URL provided. Please provide a valid URL as an argument.
  31.     exit /b 1
  32. )
  33.  
  34. rem Extract the file name from the URL
  35. for /f "tokens=7 delims=/" %%a in ("%1") do (
  36.     set file_name=%%a
  37. )
  38. for /f "tokens=1 delims=?" %%a in ("%file_name%") do (
  39.     set file_name=%%a
  40. )
  41.  
  42. rem Check if the last string contains \
  43. echo %last%|findstr "\\" >nul
  44. if errorlevel 1 (
  45.     rem No \ found, set download path as current directory
  46.     set download_dir=%cd%
  47.     echo !
  48.     echo %file_name% will be downloaded to the current directory
  49. ) else (
  50.     rem \ found, set download path as last string
  51.     set download_dir=%last%
  52.     echo !
  53.     echo %file_name% will be downloaded to %last%
  54. )
  55.  
  56.  
  57. rem Set the aria2c executable path
  58. set aria2c_path=aria2c.exe
  59.  
  60. rem Download the file using aria2c
  61. %aria2c_path% -c -V -x 10 -d "%download_dir%" -o "%file_name%" "%1"
  62.  
  63. rem Check the exit code of aria2c
  64. if %errorlevel% equ 0 (
  65.     echo Download completed successfully.
  66. ) else (
  67.     echo Download failed with error code %errorlevel%.
  68. )
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement