Spaces:
Sleeping
Sleeping
| from huggingface_hub import HfApi, create_repo, upload_file | |
| import os | |
| class HFDeployer: | |
| """ | |
| Law XII Component: The Ascension Engine (Production Version) | |
| Uses the Hugging Face Hub SDK to manage real TGI Spaces. | |
| """ | |
| def __init__(self, api_bridge): | |
| self.api = api_bridge | |
| self.hf_api = HfApi() | |
| def deploy_space(self, space_name, files): | |
| """ | |
| Creates/Updates a Hugging Face Space and uploads all TGI core files. | |
| """ | |
| token = self.api.vault.access_data("HF_TOKEN", self.api.m, self.api.k) | |
| if not token: | |
| print("[!] HF DEPLOYER: Access Denied. Token not found.") | |
| return False | |
| # Get current user from token | |
| try: | |
| user_info = self.hf_api.whoami(token=token) | |
| username = user_info['name'] | |
| except: | |
| username = "LOOFYYLO" | |
| repo_id = f"{username}/{space_name}" | |
| print(f"\n[*] [HF DEPLOYER]: Synchronizing Space '{repo_id}'...") | |
| try: | |
| # 1. Ensure Space exists | |
| create_repo( | |
| repo_id=repo_id, | |
| token=token, | |
| repo_type="space", | |
| space_sdk="gradio", | |
| exist_ok=True | |
| ) | |
| # 2. Upload Files | |
| for file_path in files: | |
| if not os.path.exists(file_path): continue | |
| print(f" [>] Uploading {file_path}...") | |
| upload_file( | |
| path_or_fileobj=file_path, | |
| path_in_repo=file_path, | |
| repo_id=repo_id, | |
| repo_type="space", | |
| token=token | |
| ) | |
| print(f"\n[✓] ASCENSION COMPLETE: TGI is live at huggingface.co/spaces/{repo_id}") | |
| return True | |
| except Exception as e: | |
| print(f" [-] DEPLOYMENT ERROR: {str(e)}") | |
| return False | |
| if __name__ == "__main__": | |
| from fso_external_api_bridge import ExternalAPIBridge | |
| from fso_token_vault_setup import setup_token_vault | |
| v = setup_token_vault() | |
| api = ExternalAPIBridge(v) | |
| deployer = HFDeployer(api) | |
| print("\n--- [ASCENSION ENGINE]: SDK Integrated & Ready ---") | |