txt2liveportrait / temp.py
yerang's picture
Upload temp.py with huggingface_hub
0a2f6b8 verified
raw
history blame
2.15 kB
# 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 upload_file
from tqdm import tqdm
# Hugging Face ํ† ํฐ์„ ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋กœ ์„ค์ •
hf_token = os.getenv("HF_TOKEN")
# ํ˜„์žฌ ๋””๋ ‰ํ† ๋ฆฌ ์ „์ฒด๋ฅผ ์—…๋กœ๋“œ
folder_path = "." # ํ˜„์žฌ ๋””๋ ‰ํ† ๋ฆฌ
repo_id = "yerang/txt2liveportrait" # ๋ฆฌํฌ์ง€ํ† ๋ฆฌ ID
# ์ œ์™ธํ•  ํŒŒ์ผ ํฌ๊ธฐ (๋‹จ์œ„: ๋ฐ”์ดํŠธ, ์—ฌ๊ธฐ์„œ๋Š” 100MB ์ด์ƒ์ธ ํŒŒ์ผ์„ ์ œ์™ธ)
max_file_size = 100 * 1024 * 1024 # 100MB
# ์ œ์™ธํ•  ํด๋” ๋ฆฌ์ŠคํŠธ
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)
# ํŒŒ์ผ ํฌ๊ธฐ ํ™•์ธ ํ›„, ์„ค์ •ํ•œ ํฌ๊ธฐ ์ดํ•˜์˜ ํŒŒ์ผ๋งŒ ์ถ”๊ฐ€
if os.path.getsize(full_path) < max_file_size:
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 ํ† ํฐ
)