# import os | |
# from huggingface_hub import upload_folder | |
# # Hugging Face ํ ํฐ์ ํ๊ฒฝ ๋ณ์๋ก ์ค์ | |
# hf_token = os.getenv("HF_TOKEN") | |
# # ํ์ฌ ๋๋ ํ ๋ฆฌ ์ ์ฒด๋ฅผ ์ ๋ก๋ | |
# folder_path = "." # ํ์ฌ ๋๋ ํ ๋ฆฌ | |
# # Hugging Face ๋ฆฌํฌ์งํ ๋ฆฌ์ ํด๋ ์ ๋ก๋ | |
# upload_folder( | |
# folder_path=folder_path, # ์ ๋ก๋ํ ํด๋ ๊ฒฝ๋ก | |
# path_in_repo="", # ๋ฆฌํฌ์งํ ๋ฆฌ ๋ด ๊ฒฝ๋ก (๋ฃจํธ๋ก ์ค์ ) | |
# repo_id="yerang/txt2liveportrait", # ๋ฆฌํฌ์งํ ๋ฆฌ ID | |
# token=hf_token # ํ๊ฒฝ ๋ณ์์์ ํ ํฐ ์ฌ์ฉ | |
# ) | |
import os | |
from huggingface_hub import HfApi, upload_file | |
from tqdm import tqdm | |
# Hugging Face ํ ํฐ์ ํ๊ฒฝ ๋ณ์๋ก ์ค์ | |
hf_token = os.getenv("HF_TOKEN") | |
# ํ์ฌ ๋๋ ํ ๋ฆฌ ์ ์ฒด๋ฅผ ์ ๋ก๋ | |
folder_path = "." # ํ์ฌ ๋๋ ํ ๋ฆฌ | |
repo_id = "yerang/txt2liveportrait" # ๋ฆฌํฌ์งํ ๋ฆฌ ID | |
# Hugging Face API ์ธ์คํด์ค ์์ฑ | |
api = HfApi() | |
# ์ ์ธํ ํด๋ ๋ฐ ํ์ผ ํจํด ์ค์ | |
exclude_dirs = {".git", ".ipynb_checkpoints"} | |
exclude_files = {".gitignore", ".gitattributes", ".gitmodules"} | |
# ํ์ผ ๋ชฉ๋ก ๊ฐ์ ธ์ค๊ธฐ (ํํฐ๋ง ํฌํจ) | |
file_paths = [] | |
for root, dirs, files in os.walk(folder_path): | |
# ์ ์ธํ ๋๋ ํ ๋ฆฌ๋ฅผ ํ์ ๋์์์ ์ ์ธ | |
dirs[:] = [d for d in dirs if d not in exclude_dirs] | |
for file in files: | |
if file not in exclude_files: # ์ ์ธํ ํ์ผ ํํฐ๋ง | |
full_path = os.path.join(root, file) | |
rel_path_in_repo = os.path.relpath(full_path, folder_path) | |
file_paths.append((full_path, rel_path_in_repo)) | |
# ํ์ผ ์ ๋ก๋ ์งํ ์ํฉ ํ์ | |
for full_path, rel_path_in_repo in tqdm(file_paths, desc="Uploading files"): | |
upload_file( | |
path_or_fileobj=full_path, # ์ค์ ํ์ผ ๊ฒฝ๋ก | |
path_in_repo=rel_path_in_repo, # ๋ฆฌํฌ์งํ ๋ฆฌ ๋ด ๊ฒฝ๋ก | |
repo_id=repo_id, # ๋ฆฌํฌ์งํ ๋ฆฌ ID | |
token=hf_token # Hugging Face ํ ํฐ | |
) | |