File size: 1,549 Bytes
12e91a8
 
 
 
8f12b2c
12e91a8
 
 
 
 
 
 
 
 
 
 
 
 
8f12b2c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12e91a8
 
8f12b2c
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
import os
from huggingface_hub import HfApi
import time

def upload_with_retry(folder_path, repo_id, max_retries=10):
    api = HfApi()
    
    # 获取所有文件
    files = []
    for root, _, filenames in os.walk(folder_path):
        for filename in filenames:
            if not any(pattern in filename for pattern in [".git"]):
                full_path = os.path.join(root, filename)
                relative_path = os.path.relpath(full_path, folder_path)
                files.append((full_path, relative_path))
    
    print(f"Found {len(files)} files to upload")
    
    for file_path, path_in_repo in files:
        for attempt in range(max_retries):
            try:
                print(f"Uploading {path_in_repo} (Attempt {attempt + 1} of {max_retries})")
                api.upload_file(
                    path_or_fileobj=file_path,
                    path_in_repo=path_in_repo,
                    repo_id=repo_id,
                    repo_type="model"
                )
                print(f"Successfully uploaded {path_in_repo}")
                break
            except Exception as e:
                print(f"Error uploading {path_in_repo}: {e}")
                if attempt < max_retries - 1:
                    wait_time = 10 * (attempt + 1)
                    print(f"Retrying in {wait_time} seconds...")
                    time.sleep(wait_time)
                else:
                    print(f"Max retries reached. Failed to upload {path_in_repo}")

# 使用
upload_with_retry(".", "Neph0s/CoSER-Llama-3.1-70B")