""" PromptForge — Hugging Face Space Uploader ========================================== Usage: pip install huggingface_hub python upload_to_hf.py You will be prompted to enter your HF token securely (never paste in chat). """ import os import sys import getpass from pathlib import Path # ── Check huggingface_hub is installed ──────────────────────────── try: from huggingface_hub import HfApi, create_repo, login except ImportError: print("[ERROR] huggingface_hub is not installed.") print(" Run: pip install huggingface_hub") sys.exit(1) # ── Config ──────────────────────────────────────────────────────── REPO_ID = "Really-amin/promptforge" # Change username if needed REPO_TYPE = "space" SPACE_SDK = "docker" PRIVATE = False COMMIT_MSG = "Upload PromptForge v1.0 — Structured prompt generator for Google AI Studio" # Files/folders to EXCLUDE from upload EXCLUDE_PATTERNS = [ "*.pyc", "__pycache__", ".env", # Never upload real .env with secrets "logs/", "promptforge/", # Nested duplicate folder "{backend/", # Artefact folder "upload_to_hf.py" # This script itself ] # ── Script root = this file's directory ─────────────────────────── PROJECT_DIR = Path(__file__).parent.resolve() def main(): print("=" * 55) print(" PromptForge — Hugging Face Space Uploader") print("=" * 55) print(f"\n Project folder : {PROJECT_DIR}") print(f" Target repo : https://huggingface.co/spaces/{REPO_ID}") print(f" SDK : {SPACE_SDK}") print(f" Private : {PRIVATE}") print() # ── Get token securely ───────────────────────────────────────── token = os.environ.get("HF_API_KEY") or os.environ.get("HF_TOKEN") if not token: print(" Enter your Hugging Face token (input is hidden):") token = getpass.getpass(" HF Token > ").strip() if not token or not token.startswith("hf_"): print("[ERROR] Invalid token format. Must start with 'hf_'") sys.exit(1) # ── Authenticate ─────────────────────────────────────────────── print("\n[1/4] Authenticating with Hugging Face...") try: login(token=token, add_to_git_credential=False) api = HfApi(token=token) user = api.whoami() print(f" ✅ Logged in as: {user['name']}") except Exception as e: print(f" ❌ Authentication failed: {e}") sys.exit(1) # ── Create or verify Space ───────────────────────────────────── print(f"\n[2/4] Creating Space '{REPO_ID}' (skips if exists)...") try: url = create_repo( repo_id=REPO_ID, repo_type=REPO_TYPE, space_sdk=SPACE_SDK, private=PRIVATE, token=token, exist_ok=True, ) print(f" ✅ Space ready: {url}") except Exception as e: print(f" ❌ Failed to create Space: {e}") sys.exit(1) # ── Upload folder ────────────────────────────────────────────── print(f"\n[3/4] Uploading project files...") print(f" Source: {PROJECT_DIR}") try: api.upload_folder( folder_path=str(PROJECT_DIR), repo_id=REPO_ID, repo_type=REPO_TYPE, token=token, commit_message=COMMIT_MSG, ignore_patterns=EXCLUDE_PATTERNS, ) print(" ✅ All files uploaded successfully!") except Exception as e: print(f" ❌ Upload failed: {e}") sys.exit(1) # ── Done ─────────────────────────────────────────────────────── print(f"\n[4/4] Done!") print(f"\n 🚀 Your Space is live at:") print(f" https://huggingface.co/spaces/{REPO_ID}") print(f"\n 📖 API docs will be at:") print(f" https://huggingface.co/spaces/{REPO_ID} → /docs") print() if __name__ == "__main__": main()