-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload_to_huggingface.py
More file actions
44 lines (34 loc) · 1.24 KB
/
upload_to_huggingface.py
File metadata and controls
44 lines (34 loc) · 1.24 KB
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
import os
from huggingface_hub import HfApi, list_repo_files
# Set up the Hugging Face Hub API
api = HfApi()
# Repository ID
repo_id = "datvo06/fine-tuned-layoutlm"
# Find all .bin files in the current directory and its subdirectories
bin_files = []
repo_files = list_repo_files(repo_id=repo_id, repo_type='model')
for root, dirs, files in os.walk("."):
for file in files:
if file.endswith(".bin") or file.endswith('config.json'):
relative_path = os.path.relpath(os.path.join(root, file), ".")
if relative_path not in repo_files:
bin_files.append(os.path.join(root, file))
# Upload each .bin file to the Hugging Face Hub
for file_path in bin_files:
# Get the relative path of the file
relative_path = os.path.relpath(file_path, ".")
# Upload the file to the repository
api.upload_file(
path_or_fileobj=file_path,
path_in_repo=relative_path,
repo_id=repo_id,
repo_type="model",
)
print(f"Uploaded {file_path} to {repo_id}/{relative_path}")
api.upload_file(
path_or_fileobj="synthesized_programs.zip",
path_in_repo="synthesized_programs.zip",
repo_id=repo_id,
repo_type="model",
)
print("All .bin files uploaded successfully!")