Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Arabic App Full Server Deployer (Hybrid Node.js + Python) | |
| ========================================================= | |
| Usage: | |
| python3 deploy_full_server.py --token hf_xxxxxxxxxxxx --username YOUR_HF_USERNAME | |
| """ | |
| import argparse | |
| import sys | |
| from pathlib import Path | |
| def main(): | |
| parser = argparse.ArgumentParser(description="Deploy Hybrid Arabic App Server to HF Spaces") | |
| parser.add_argument("--token", required=True, help="HF Write token (hf_...)") | |
| parser.add_argument("--username", required=True, help="HF username") | |
| parser.add_argument("--space", default="arab-app-server", help="Space name") | |
| parser.add_argument("--gemini_token", help="Gemini API token to set as secret") | |
| args = parser.parse_args() | |
| try: | |
| from huggingface_hub import HfApi, create_repo | |
| except ImportError: | |
| print("β huggingface_hub not installed") | |
| sys.exit(1) | |
| api = HfApi(token=args.token) | |
| repo_id = f"{args.username}/{args.space}" | |
| print(f"π Deploying to: https://huggingface.co/spaces/{repo_id}") | |
| # 1. Create the Space | |
| create_repo( | |
| repo_id=repo_id, | |
| repo_type="space", | |
| space_sdk="docker", | |
| token=args.token, | |
| exist_ok=True, | |
| private=False, | |
| ) | |
| # 1.5 Set Gemini Secret if provided | |
| if args.gemini_token: | |
| print(f"π Setting GEMINI secret...") | |
| try: | |
| api.add_space_secret( | |
| repo_id=repo_id, | |
| key="GEMINI", | |
| value=args.gemini_token, | |
| token=args.token, | |
| ) | |
| print(" β Secret set successfully") | |
| except Exception as e: | |
| print(f" β Failed to set secret: {e}") | |
| script_dir = Path(__file__).parent | |
| # We want to upload everything except node_modules, .env, and venvs | |
| all_files = list(script_dir.rglob("*")) | |
| files_to_upload = [] | |
| ignore_patterns = [ | |
| "node_modules", ".env", "tts_venv", "venv", ".git", "data", | |
| "__pycache__", ".DS_Store", "Dockerfile.hf" # Dockerfile.hf will be uploaded as Dockerfile | |
| ] | |
| for f in all_files: | |
| if f.is_file(): | |
| rel_path = f.relative_to(script_dir) | |
| if any(p in str(rel_path) for p in ignore_patterns): | |
| continue | |
| files_to_upload.append(rel_path) | |
| print(f"π€ Uploading {len(files_to_upload) + 1} files...") | |
| # Upload Dockerfile.hf as Dockerfile | |
| api.upload_file( | |
| path_or_fileobj=str(script_dir / "Dockerfile.hf"), | |
| path_in_repo="Dockerfile", | |
| repo_id=repo_id, | |
| repo_type="space", | |
| token=args.token, | |
| ) | |
| for rel_path in files_to_upload: | |
| try: | |
| api.upload_file( | |
| path_or_fileobj=str(script_dir / rel_path), | |
| path_in_repo=str(rel_path), | |
| repo_id=repo_id, | |
| repo_type="space", | |
| token=args.token, | |
| ) | |
| print(f" β {rel_path}") | |
| except Exception as e: | |
| print(f" β {rel_path}: {e}") | |
| print(f"\nβ Deployment complete: https://huggingface.co/spaces/{repo_id}") | |
| print("\nβ οΈ IMPORTANT: Add your GEMINI API key to the Space's Secrets in Settings!") | |
| if __name__ == "__main__": | |
| main() | |