#!/usr/bin/env python3 """ deploy_to_hf.py — Sube el proyecto WebToAPK a Hugging Face Spaces. Uso: pip install huggingface_hub python deploy_to_hf.py --token hf_xxxx --repo tu-usuario/webto-apk """ import argparse import os from pathlib import Path def main(): parser = argparse.ArgumentParser(description="Deploy WebToAPK a Hugging Face Spaces") parser.add_argument("--token", required=True, help="HF API token (hf_...)") parser.add_argument("--repo", required=True, help="Nombre del repo: usuario/nombre-space") parser.add_argument("--private",action="store_true", help="Hacer el Space privado") args = parser.parse_args() try: from huggingface_hub import HfApi, create_repo, upload_folder except ImportError: print("❌ Instala huggingface_hub: pip install huggingface_hub") return api = HfApi(token=args.token) print(f"📦 Creando Space: {args.repo}") create_repo( repo_id=args.repo, repo_type="space", space_sdk="docker", private=args.private, token=args.token, exist_ok=True, ) project_root = Path(__file__).parent ignore_patterns = [ "__pycache__", "*.pyc", ".git", "output/*.apk", "*.egg-info", ".env", ".DS_Store" ] print("⬆️ Subiendo archivos...") upload_folder( folder_path=str(project_root), repo_id=args.repo, repo_type="space", token=args.token, ignore_patterns=ignore_patterns, ) space_url = f"https://huggingface.co/spaces/{args.repo}" print(f"\n✅ Space desplegado exitosamente!") print(f"🌐 URL: {space_url}") print(f"\n💡 Nota: El Space tardará ~5-10 min en construir la imagen Docker.") if __name__ == "__main__": main()