|
# 关于 |
|
## 此huggingface库主要存储本人电脑的一些重要文件 |
|
## 如果无法下载文件,使用huggingface中国镜像站: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等中转服务器上传,上传速率60MB/s。 |