Download scripts/deploy_to_hf.py from khiemdztv/civic-backup: direct link, hf CLI and curl.
- Browser
- Download file 1.97 kB
-
https://huggingface.co/khiemdztv/civic-backup/resolve/main/scripts/deploy_to_hf.py
- Command line
-
hf download hf://khiemdztv/civic-backup/scripts/deploy_to_hf.py
-
curl -L -o deploy_to_hf.py https://huggingface.co/khiemdztv/civic-backup/resolve/main/scripts/deploy_to_hf.py
1.97 kB
| #!/usr/bin/env python3 | |
| """Script đẩy giao diện mới lên Hugging Face Space khiemdztv/civic-ai-demo.""" | |
| import argparse | |
| import os | |
| import sys | |
| from pathlib import Path | |
| try: | |
| from huggingface_hub import HfApi | |
| except ImportError: | |
| print("Lỗi: Cần cài đặt huggingface_hub: pip install huggingface_hub", file=sys.stderr) | |
| sys.exit(1) | |
| REPO_ID = "khiemdztv/civic-ai-demo" | |
| ROOT_DIR = Path(__file__).resolve().parent.parent | |
| def main(): | |
| parser = argparse.ArgumentParser(description="Đẩy giao diện lên HF Space") | |
| parser.add_argument( | |
| "--type", | |
| choices=["static", "gradio"], | |
| default="static", | |
| help="Loại giao diện: 'static' (static_space/) hoặc 'gradio' (hf_space/)" | |
| ) | |
| parser.add_argument( | |
| "--token", | |
| default=os.environ.get("HF_TOKEN"), | |
| help="Hugging Face Write Token (hoặc đặt biến môi trường HF_TOKEN)" | |
| ) | |
| args = parser.parse_args() | |
| target_dir = ROOT_DIR / ("static_space" if args.type == "static" else "hf_space") | |
| if not target_dir.exists(): | |
| print(f"Lỗi: Không tìm thấy thư mục {target_dir}", file=sys.stderr) | |
| sys.exit(1) | |
| print(f"🚀 Chuẩn bị cập nhật Space [{REPO_ID}] với giao diện [{args.type}]...") | |
| print(f"📁 Thư mục nguồn: {target_dir}") | |
| api = HfApi(token=args.token) | |
| try: | |
| api.upload_folder( | |
| folder_path=str(target_dir), | |
| repo_id=REPO_ID, | |
| repo_type="space", | |
| commit_message=f"Update CIVIC AI to {args.type} UI", | |
| ) | |
| print("✅ Đã cập nhật thành công lên https://huggingface.co/spaces/" + REPO_ID) | |
| except Exception as e: | |
| print(f"❌ Lỗi khi upload: {e}", file=sys.stderr) | |
| print("Gợi ý: Nếu chưa đăng nhập HF, hãy truyền --token <HF_WRITE_TOKEN> hoặc chạy 'huggingface-cli login'.", file=sys.stderr) | |
| sys.exit(1) | |
| if __name__ == "__main__": | |
| main() | |