--- 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 "https://huggingface.co./AstraliteHeart/pony-diffusion-v6/resolve/main/v6.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/Qgz_RzYYRegtZfttIfrre.png)