File size: 4,244 Bytes
36b194b
 
 
 
 
 
 
 
5640e1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7576f54
 
 
 
 
4abab71
7576f54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fcd8841
 
 
 
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
---
license: apache-2.0
language:
- ch
---
# 此huggingface库主要存储本人电脑的一些重要文件
## 如果无法下载文件,把下载链接的huggingface.co改成hf-mirror.com 即可
## 如果你也想要在此处永久备份文件,可以参考我的上传代码:
```python
# 功能函数,清理打包上传
from pathlib import Path
from huggingface_hub import HfApi, login

repo_id = 'ACCC1380/private-model'
yun_folders = ['/kaggle/input']


def hugface_upload(yun_folders, repo_id):
    if 5 == 5:
        hugToken = '********************' #改成你的huggingface_token
        if hugToken != '':
            login(token=hugToken)
            api = HfApi()
            print("HfApi 类已实例化")
            print("开始上传文件...")
            for yun_folder in yun_folders:
                folder_path = Path(yun_folder)
                if folder_path.exists() and folder_path.is_dir():
                    for file_in_folder in folder_path.glob('**/*'):
                        if file_in_folder.is_file():
                            try:
                                response = api.upload_file(
                                    path_or_fileobj=file_in_folder,
                                    path_in_repo=str(file_in_folder.relative_to(folder_path.parent)),
                                    repo_id=repo_id,
                                    repo_type="dataset"
                                )
                                print("文件上传完成")
                                print(f"响应: {response}")
                            except Exception as e:
                                print(f"文件 {file_in_folder} 上传失败: {e}")
                                continue
                else:
                    print(f'Error: Folder {yun_folder} does not exist')
        else:
            print(f'Error: File {huggingface_token_file} does not exist')

hugface_upload(yun_folders, repo_id)

```
## 本地电脑需要梯子环境,上传可能很慢。可以使用kaggle等中转服务器上传,下载速率400MB/s,上传速率60MB/s。
# 在kaggle上面转存模型:
- 第一步:下载文件
```notebook
!apt install -y aria2
!aria2c -x 16 -s 16 -c -k 1M "把下载链接填到这双引号里" -o "保存的文件名称.safetensors"
```
- 第二步:使用上述代码的API上传
```python
# 功能函数,清理打包上传
from pathlib import Path
from huggingface_hub import HfApi, login

repo_id = 'ACCC1380/private-model'
yun_folders = ['/kaggle/working'] #kaggle的output路径


def hugface_upload(yun_folders, repo_id):
    if 5 == 5:
        hugToken = '********************' #改成你的huggingface_token
        if hugToken != '':
            login(token=hugToken)
            api = HfApi()
            print("HfApi 类已实例化")
            print("开始上传文件...")
            for yun_folder in yun_folders:
                folder_path = Path(yun_folder)
                if folder_path.exists() and folder_path.is_dir():
                    for file_in_folder in folder_path.glob('**/*'):
                        if file_in_folder.is_file():
                            try:
                                response = api.upload_file(
                                    path_or_fileobj=file_in_folder,
                                    path_in_repo=str(file_in_folder.relative_to(folder_path.parent)),
                                    repo_id=repo_id,
                                    repo_type="dataset"
                                )
                                print("文件上传完成")
                                print(f"响应: {response}")
                            except Exception as e:
                                print(f"文件 {file_in_folder} 上传失败: {e}")
                                continue
                else:
                    print(f'Error: Folder {yun_folder} does not exist')
        else:
            print(f'Error: File {huggingface_token_file} does not exist')

hugface_upload(yun_folders, repo_id)
```
- 第三步:等待上传完成:
  


![image/png](https://cdn-uploads.huggingface.co/production/uploads/64885695cd9f45eeaab57324/CONOtCQYVOTYECE-gKbTq.png)