# 挂在谷歌云硬盘
from google.colab import drive
drive.mount('/content/drive')
# 转到文件夹
import os
os.chdir('/content/drive/MyDrive/')
!pwd
# 安装并引入包
!pip install gradio bypy huggingface_hub
import os
import shutil
from huggingface_hub import snapshot_download
from bypy import ByPy
def copy_data(source_directory,target_directory):
for entry in os.scandir(source_directory):
if entry.is_dir():
# 如果是目录,则递归复制子目录
subdirectory = os.path.join(target_directory, entry.name)
os.makedirs(subdirectory, exist_ok=True)
copy_data(entry.path, subdirectory)
else:
# 如果是文件,则直接复制到目标目录
shutil.copy2(entry.path, target_directory)
def download(repo_id):
source_directory = snapshot_download(repo_id=repo_id, cache_dir="/app/data/", force_download=True)
print("文件路径:", source_directory)
path_name = repo_id.replace("/", "---")
target_directory = f"{os.getcwd()}/download/{path_name}"
os.makedirs(target_directory, exist_ok=True) # 创建目标目录,如果目录已存在则不会报错
copy_data(source_directory, target_directory)
print("复制路径:", target_directory)
return target_directory
repo_id = "hfl/chinese-roberta-wwm-ext-large"
out_path = download(repo_id)
repo_id:
参考:
如何将 huggingface上的模型文件下载到本地
hugggingface_download.ipynb