File size: 1,188 Bytes
d61c901
90d0088
0e63074
d61c901
2be7e48
d61c901
 
 
 
2be7e48
d61c901
0e63074
d61c901
2be7e48
 
 
d61c901
 
 
 
90d0088
33119ed
 
 
 
 
 
 
2be7e48
 
 
33119ed
 
 
 
2be7e48
 
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
import os
import time
from huggingface_hub import HfApi, HfFolder

def upload_folder_to_hf_space(repo_id, folder_path, token=None):
    api = HfApi()
    token = token or HfFolder.get_token()

    if not token:
        raise ValueError("Hugging Face token not found. Log in or provide a token.")

    for root, _, files in os.walk(folder_path):
        for file in files:
            if file.startswith('.') or file.endswith('~'):
                continue

            local_path = os.path.join(root, file)
            remote_path = os.path.relpath(local_path, folder_path)

            print(f"Uploading {local_path} to {repo_id}/{remote_path}...")
            time.sleep(2)
            api.upload_file(
                path_or_fileobj=local_path,
                path_in_repo=remote_path,
                repo_id=repo_id,
                repo_type="space",
                token=token
            )

    print("Upload completed successfully!")

# 使用例
repo_id = "OzoneAsai/CnJaFlashC-1"
folder_path = "./"
token = os.getenv("HF_TOKEN")  # 環境変数に設定したトークンを使用

upload_folder_to_hf_space(repo_id, folder_path, token)