Spaces:
Sleeping
Sleeping
Download startup.py from KeyBow/MediaMasterAsyncPre: direct link, hf CLI and curl.
- Browser
- Download file 1.44 kB
-
https://huggingface.co/spaces/KeyBow/MediaMasterAsyncPre/resolve/main/startup.py
- Command line
-
hf download hf://spaces/KeyBow/MediaMasterAsyncPre/startup.py
-
curl -L -o startup.py https://huggingface.co/spaces/KeyBow/MediaMasterAsyncPre/resolve/main/startup.py
1.44 kB
| """ | |
| startup.py | |
| コンテナ起動時に HuggingFace Datasets からファイルを取得する。 | |
| Dockerfile の CMD で uvicorn より先に実行される。 | |
| """ | |
| import os | |
| import sys | |
| import shutil | |
| from huggingface_hub import snapshot_download | |
| REPO_ID = "KeyBow/my-download-files" | |
| LOCAL_DIR = "/app/download_files" | |
| HF_TOKEN = os.environ.get("HF_TOKEN", "") | |
| def main(): | |
| if not HF_TOKEN: | |
| print("[WARN] HF_TOKEN が設定されていません。download_files は空のまま起動します。") | |
| return | |
| # 既存ファイルをすべて削除してから取得し直す(キャッシュ対策) | |
| if os.path.exists(LOCAL_DIR): | |
| shutil.rmtree(LOCAL_DIR) | |
| os.makedirs(LOCAL_DIR, exist_ok=True) | |
| print(f"[INFO] Datasets からファイルを取得中: {REPO_ID}") | |
| try: | |
| snapshot_download( | |
| repo_id=REPO_ID, | |
| repo_type="dataset", | |
| local_dir=LOCAL_DIR, | |
| token=HF_TOKEN, | |
| local_dir_use_symlinks=False, # 実ファイルとして配置する | |
| ignore_patterns=[".gitattributes", "*.md"], | |
| ) | |
| files = [f for f in os.listdir(LOCAL_DIR) if os.path.isfile(os.path.join(LOCAL_DIR, f))] | |
| print(f"[INFO] 取得完了: {len(files)} 件 → {files}") | |
| except Exception as e: | |
| print(f"[ERROR] ファイル取得に失敗しました: {e}") | |
| sys.exit(1) | |
| if __name__ == "__main__": | |
| main() |