Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Arabic TTS β Hugging Face Spaces Deployer | |
| ========================================== | |
| CrΓ©e et dΓ©ploie le serveur TTS sur HF Spaces en une commande. | |
| Usage: | |
| python3 deploy_to_hf.py --token hf_xxxxxxxxxxxx --username YOUR_HF_USERNAME | |
| Obtenez votre token sur: https://huggingface.co/settings/tokens | |
| (Type: Write access) | |
| """ | |
| import argparse | |
| import os | |
| import sys | |
| import shutil | |
| import tempfile | |
| from pathlib import Path | |
| # βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| SPACE_NAME = "arabic-tts" | |
| SPACE_SDK = "docker" | |
| SPACE_TITLE = "Arabic TTS - FastPitch Neural" | |
| # βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| def main(): | |
| parser = argparse.ArgumentParser(description="Deploy Arabic TTS 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=SPACE_NAME, help="Space name (default: arabic-tts)") | |
| args = parser.parse_args() | |
| try: | |
| from huggingface_hub import HfApi, create_repo | |
| except ImportError: | |
| print("β huggingface_hub not installed in this venv") | |
| sys.exit(1) | |
| api = HfApi(token=args.token) | |
| repo_id = f"{args.username}/{args.space}" | |
| print(f"π Deploying Arabic TTS to: https://huggingface.co/spaces/{repo_id}") | |
| print() | |
| # 1. Create the Space if it doesn't exist | |
| print("π¦ Creating HF Space (if not exists)...") | |
| try: | |
| create_repo( | |
| repo_id=repo_id, | |
| repo_type="space", | |
| space_sdk=SPACE_SDK, | |
| token=args.token, | |
| exist_ok=True, | |
| private=False, | |
| ) | |
| print(f" β Space ready: https://huggingface.co/spaces/{repo_id}") | |
| except Exception as e: | |
| print(f" β Failed to create space: {e}") | |
| sys.exit(1) | |
| # 2. Prepare files to upload | |
| script_dir = Path(__file__).parent | |
| files_to_upload = { | |
| # source path (local) : dest path (in HF Space repo) | |
| script_dir / "tts_server.py" : "tts_server.py", | |
| script_dir / "hf_space/Dockerfile" : "Dockerfile", | |
| script_dir / "hf_space/requirements.txt" : "requirements.txt", | |
| script_dir / "hf_space/README.md" : "README.md", | |
| } | |
| print(f"\nπ€ Uploading {len(files_to_upload)} files...") | |
| for src, dest in files_to_upload.items(): | |
| if not src.exists(): | |
| print(f" β οΈ Missing: {src}") | |
| continue | |
| try: | |
| api.upload_file( | |
| path_or_fileobj=str(src), | |
| path_in_repo=dest, | |
| repo_id=repo_id, | |
| repo_type="space", | |
| token=args.token, | |
| commit_message=f"Deploy: {dest}", | |
| ) | |
| print(f" β {dest}") | |
| except Exception as e: | |
| print(f" β {dest}: {e}") | |
| space_url = f"https://huggingface.co/spaces/{repo_id}" | |
| tts_url = f"https://{args.username}-{args.space}.hf.space" | |
| print() | |
| print("=" * 60) | |
| print("β DEPLOYMENT COMPLETE") | |
| print("=" * 60) | |
| print() | |
| print(f"π Space URL: {space_url}") | |
| print(f"ποΈ TTS API: {tts_url}/tts?text=Ψ§ΩΨ³ΩΩΩΩΨ§Ω Ω") | |
| print(f"β€οΈ Health: {tts_url}/health") | |
| print() | |
| print("β³ HF is building the Docker image (~3-5 minutes)") | |
| print(" Watch build logs at:") | |
| print(f" {space_url}?logs=build") | |
| print() | |
| print("π NEXT STEP β Add to your frontend .env.production:") | |
| print() | |
| print(f" VITE_TTS_URL={tts_url}") | |
| print() | |
| print("Then rebuild your frontend:") | |
| print(" cd front && npm run build") | |
| print() | |
| if __name__ == "__main__": | |
| main() | |