Spaces:
Sleeping
Sleeping
Upload the python files with Huggingface upload and download functions
Browse files- download.py +18 -0
- upload.py +36 -0
download.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from huggingface_hub import hf_hub_download
|
2 |
+
from huggingface_hub import snapshot_download
|
3 |
+
|
4 |
+
#download files
|
5 |
+
def download_file(repo_name, filename, repo_type):
|
6 |
+
|
7 |
+
file_location = hf_hub_download(repo_id=repo_name, filename=filename,repo_type=repo_type)
|
8 |
+
return file_location
|
9 |
+
|
10 |
+
#download a folder
|
11 |
+
def download_folder(repo_name, revision='main'):
|
12 |
+
|
13 |
+
folder_location = snapshot_download(repo_id=repo_name, revision=revision)
|
14 |
+
|
15 |
+
return folder_location
|
16 |
+
|
17 |
+
|
18 |
+
|
upload.py
ADDED
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from huggingface_hub import hf_hub_download
|
2 |
+
from huggingface_hub import login
|
3 |
+
from huggingface_hub import HfApi
|
4 |
+
from huggingface_hub import snapshot_download
|
5 |
+
|
6 |
+
#not that when passing a file path with "-" in the name add double slashes so it's accpeted by Python
|
7 |
+
|
8 |
+
|
9 |
+
def upload_file(token, local_path, repo_path, repo_id, repo_type):
|
10 |
+
|
11 |
+
#Whenever you want to upload files to the Hub, you need to log in to your Hugging Face account
|
12 |
+
login(token=token)
|
13 |
+
|
14 |
+
api = HfApi()
|
15 |
+
|
16 |
+
api.upload_file(
|
17 |
+
path_or_fileobj=local_path,
|
18 |
+
path_in_repo=repo_path,
|
19 |
+
repo_id=repo_id,
|
20 |
+
repo_type=repo_type,
|
21 |
+
)
|
22 |
+
|
23 |
+
def upload_folder(token, local_path, repo_path, repo_id, repo_type,ignore_patterns):
|
24 |
+
|
25 |
+
#Whenever you want to upload files to the Hub, you need to log in to your Hugging Face account
|
26 |
+
login(token=token)
|
27 |
+
|
28 |
+
api = HfApi()
|
29 |
+
|
30 |
+
api.upload_folder(
|
31 |
+
folder_path=local_path,
|
32 |
+
path_in_repo=repo_path,
|
33 |
+
repo_id=repo_id,
|
34 |
+
repo_type=repo_type,
|
35 |
+
ignore_patterns=ignore_patterns,
|
36 |
+
)
|