Manifesto_Explainer / deploy_hf.py
Sa-m's picture
Upload folder using huggingface_hub
c00891c verified
Raw
History Blame Contribute Delete
1.39 kB
import os
from huggingface_hub import HfApi
def deploy():
# 1. Get your Hugging Face Token from https://huggingface.co/settings/tokens
# 2. Get your Space ID (e.g. "username/manifesto-explainer")
token = input("Enter your Hugging Face Write Token: ").strip()
repo_id = input("Enter your Space Repository ID (e.g., your-username/manifesto-explainer): ").strip()
if not token or not repo_id:
print("Error: Token and Repo ID are required.")
return
api = HfApi()
print(f"🚀 Uploading project to Hugging Face Space: {repo_id}...")
try:
# This will upload the entire current directory to the Space
# It respects .gitignore and .dockerignore
api.upload_folder(
folder_path=".",
repo_id=repo_id,
repo_type="space",
token=token,
ignore_patterns=["*.env", "__pycache__/*", "venv/*", ".git/*"]
)
print("\n✅ Success! Your files have been uploaded.")
print(f"🔗 View your Space here: https://huggingface.co/spaces/{repo_id}")
print("\n⚠️ IMPORTANT: Don't forget to go to Space Settings > Variables and secrets")
print("and add your GROQ_API_KEY and GEMINI_API_KEY as Secrets.")
except Exception as e:
print(f"\n❌ Error during upload: {e}")
if __name__ == "__main__":
deploy()