Spaces:
Runtime error
Runtime error
| """ | |
| 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() | |