import os from huggingface_hub import HfApi def deploy(): # Load token from ~/.cache/huggingface/token token_path = os.path.expanduser("~/.cache/huggingface/token") if not os.path.exists(token_path): print("HF Token not found in ~/.cache/huggingface/token") return with open(token_path, "r") as f: token = f.read().strip() api = HfApi(token=token) # Get user info to know the namespace user_info = api.whoami() username = user_info['name'] space_name = "Rukku" repo_id = f"{username}/{space_name}" print(f"Creating Space: {repo_id}") try: api.create_repo(repo_id=repo_id, repo_type="space", space_sdk="gradio", exist_ok=True) print("Space created or already exists.") except Exception as e: print(f"Error creating space: {e}") return try: pass api.delete_file("historical_cache.pkl", repo_id=repo_id, repo_type="space") api.delete_file("yfinance.cache", repo_id=repo_id, repo_type="space") except Exception: pass print("Uploading files...") # We will upload the necessary files. # We need: app.py, requirements.txt, backtest (dir), demo_interface (dir) api.upload_folder( folder_path=".", repo_id=repo_id, repo_type="space", ignore_patterns=[".git*", "__pycache__*", "results*", "venv*", "*.parquet", "*.pkl", "*.cache"] ) print(f"Deployed successfully! View your space at: https://huggingface.co/spaces/{repo_id}") if __name__ == "__main__": deploy()