-
Notifications
You must be signed in to change notification settings - Fork 0
/
get_hf_lfs_files
executable file
路74 lines (54 loc) 路 2.18 KB
/
get_hf_lfs_files
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
#!/usr/bin/bash
# Copyright 2023 evdcush
#=============================================================================#
# CLONE REPO #
#=============================================================================#
# Get the repo URL from the clipboard if not provided.
# Eg: `https://huggingface.co/stabilityai/sdxl-turbo`
if [ "$#" -eq 0 ]
then
HF_REPO_URL=`xclip -o -sel clip`
else
HF_REPO_URL=$1
fi
# Get the repo name.
# eg: `sdxl-turbo`
HF_REPO_NAME=$(basename $HF_REPO_URL)
PATH_TO_HF_REPO="$PWD/$HF_REPO_NAME"
echo "HF_REPO_NAME: $HF_REPO_NAME"
# Get the repo `user/repo-name`.
# eg: `stabilityai/sdxl-turbo`
HF_REPO_TARGET=$(echo $HF_REPO_URL | cut -d '/' -f4-5)
echo "Now cloning: $HF_REPO_URL into: $PWD/$HF_REPO_NAME"
# Clone the repo.
GIT_LFS_SKIP_SMUDGE=1 git clone $HF_REPO_URL
# Enter the newly cloned repo directory, list the project root dir items.
cd $PATH_TO_HF_REPO && ls --color=tty --file-type -1hX
# Get a list of all the LFS files.
TARGET_LFS_FILES=$(git lfs ls-files | cut -d' ' -f 3)
echo "FOUND TARGET LFS FILES: $TARGET_LFS_FILES"
#=============================================================================#
# DOWNLOAD FILES #
#=============================================================================#
# Get the master branch name.
GIT_MASTER_BRANCH=$(git rev-parse --abbrev-ref HEAD)
# Base URL for LFS files on HF.
BASE_URL="https://huggingface.co/$HF_REPO_TARGET/resolve/$GIT_MASTER_BRANCH"
echo "TARGET BASE_URL: $BASE_URL"
# Prepare the target urls file for aria2c.
TARGET_LFS_FILES_LIST='target_lfs_urls.txt'
> "$TARGET_LFS_FILES_LIST" # Clear or create the file.
# Add each LFS file url to the targets file.
for lfs_file in $TARGET_LFS_FILES; do
_target_url="$BASE_URL/$lfs_file"
echo "TARGET LFS FILE URL: $_target_url"
echo "$_target_url" >> "$TARGET_LFS_FILES_LIST"
echo " out=$lfs_file" >> "$TARGET_LFS_FILES_LIST"
done
# Download the files using aria2c.
echo "BEGINNING DOWNLOAD..."
aria2c \
-i "$TARGET_LFS_FILES_LIST" \
--max-concurrent-downloads=3 \
--allow-overwrite
echo "FINISHED DOWNLOADING LFS FILES!"