tradesenseAi / scripts /deploy_to_huggingface.py
Niranjan-Murugarasu024
feat: TradeSense AI Chairman Edition production release ready for Hugging Face Spaces
0125724
Raw History Blame Contribute Delete
3.27 kB
#!/usr/bin/env python3
"""
TradeSense AI — One-Click Hugging Face Space Deployment Automation Script
"""
import os
import sys
import subprocess
import getpass
def run_cmd(cmd, check=True):
print(f"--> Running: {cmd}")
res = subprocess.run(cmd, shell=True, text=True, capture_output=True)
if res.returncode != 0 and check:
print(f"[ERROR] Command failed:\n{res.stderr}")
return False, res.stderr
return True, res.stdout.strip()
def main():
print("=" * 65)
print(" TRADESENSE AI — HUGGING FACE SPACES DEPLOYMENT ASSISTANT")
print("=" * 65)
print("This script will configure git and push TradeSense AI to Hugging Face.\n")
# 1. Check git
success, git_ver = run_cmd("git --version", check=False)
if not success:
print("[FAIL] Git is not installed or not in PATH. Please install Git first.")
sys.exit(1)
print(f"[OK] Git detected: {git_ver}")
# 2. Get HF Username & Token
username = input("\nEnter your Hugging Face Username: ").strip()
if not username:
print("[FAIL] Username cannot be empty.")
sys.exit(1)
space_name = input("Enter Space Name [default: tradesense-ai]: ").strip() or "tradesense-ai"
print("\nNote: Generate a WRITE access token from: https://huggingface.co/settings/tokens")
token = getpass.getpass("Enter Hugging Face WRITE Access Token (hidden): ").strip()
if not token:
print("[FAIL] Token cannot be empty.")
sys.exit(1)
remote_url = f"https://{username}:{token}@huggingface.co/spaces/{username}/{space_name}"
direct_link = f"https://{username}-{space_name}.hf.space"
portal_link = f"https://huggingface.co/spaces/{username}/{space_name}"
print("\n[1/4] Checking git status and staging files...")
run_cmd("git add Dockerfile requirements.txt README.md .dockerignore backend quant static templates data", check=False)
print("[2/4] Creating deployment commit...")
run_cmd('git commit -m "Deploy TradeSense AI Chairman Edition to Hugging Face Spaces"', check=False)
print("[3/4] Configuring Hugging Face git remote...")
# Remove existing remote if present
run_cmd("git remote remove huggingface", check=False)
ok, _ = run_cmd(f"git remote add huggingface {remote_url}")
if not ok:
print("[FAIL] Could not add remote.")
sys.exit(1)
print("[4/4] Pushing code to Hugging Face Spaces...")
ok, out = run_cmd("git push -f huggingface main")
if not ok:
# Try pushing master branch if main doesn't exist
ok2, out2 = run_cmd("git push -f huggingface master:main")
if not ok2:
print("[FAIL] Push failed. Please check that you created the Space on huggingface.co first!")
print(f"Create Space here: https://huggingface.co/new-space (Choose Docker SDK)")
sys.exit(1)
print("\n" + "=" * 65)
print(" DEPLOYMENT TRIGGERED SUCCESSFULLY!")
print("=" * 65)
print(f"Hugging Face Portal: {portal_link}")
print(f"DIRECT REAL-TIME LINK: {direct_link}")
print("\nHugging Face is now building your container (~2 minutes).")
print(f"Once status turns RUNNING, access the direct link:\n --> {direct_link}\n")
if __name__ == "__main__":
main()