Really-amin commited on
Commit
6867b92
Β·
verified Β·
1 Parent(s): b2dfdb3

Upload 8 files

Browse files
Files changed (2) hide show
  1. README.md +1 -10
  2. upload_to_hf.py +119 -0
README.md CHANGED
@@ -1,12 +1,3 @@
1
- ---
2
- sdk: docker
3
- emoji: πŸš€
4
- colorFrom: yellow
5
- colorTo: yellow
6
- pinned: true
7
- thumbnail: >-
8
- https://cdn-uploads.huggingface.co/production/uploads/66367933cc7af105efbcd2dc/4Ylfqn8qX4MG1OG6m4jxW.png
9
- ---
10
  # PromptForge v4.0
11
 
12
  > **Structured prompt generator for Google AI Studio.**
@@ -251,4 +242,4 @@ Set `HF_API_KEY` and/or `GOOGLE_API_KEY` as environment variables in your dashbo
251
 
252
  ## License
253
 
254
- MIT β€” use freely, contribute back.
 
 
 
 
 
 
 
 
 
 
1
  # PromptForge v4.0
2
 
3
  > **Structured prompt generator for Google AI Studio.**
 
242
 
243
  ## License
244
 
245
+ MIT β€” use freely, contribute back.
upload_to_hf.py ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ PromptForge β€” Hugging Face Space Uploader
3
+ ==========================================
4
+ Usage:
5
+ pip install huggingface_hub
6
+ python upload_to_hf.py
7
+
8
+ You will be prompted to enter your HF token securely (never paste in chat).
9
+ """
10
+
11
+ import os
12
+ import sys
13
+ import getpass
14
+ from pathlib import Path
15
+
16
+ # ── Check huggingface_hub is installed ────────────────────────────
17
+ try:
18
+ from huggingface_hub import HfApi, create_repo, login
19
+ except ImportError:
20
+ print("[ERROR] huggingface_hub is not installed.")
21
+ print(" Run: pip install huggingface_hub")
22
+ sys.exit(1)
23
+
24
+ # ── Config ────────────────────────────────────────────────────────
25
+ REPO_ID = "Really-amin/promptforge" # Change username if needed
26
+ REPO_TYPE = "space"
27
+ SPACE_SDK = "docker"
28
+ PRIVATE = False
29
+ COMMIT_MSG = "Upload PromptForge v1.0 β€” Structured prompt generator for Google AI Studio"
30
+
31
+ # Files/folders to EXCLUDE from upload
32
+ EXCLUDE_PATTERNS = [
33
+ "*.pyc",
34
+ "__pycache__",
35
+ ".env", # Never upload real .env with secrets
36
+ "logs/",
37
+ "promptforge/", # Nested duplicate folder
38
+ "{backend/", # Artefact folder
39
+ "upload_to_hf.py" # This script itself
40
+ ]
41
+
42
+ # ── Script root = this file's directory ───────────────────────────
43
+ PROJECT_DIR = Path(__file__).parent.resolve()
44
+
45
+ def main():
46
+ print("=" * 55)
47
+ print(" PromptForge β€” Hugging Face Space Uploader")
48
+ print("=" * 55)
49
+ print(f"\n Project folder : {PROJECT_DIR}")
50
+ print(f" Target repo : https://huggingface.co/spaces/{REPO_ID}")
51
+ print(f" SDK : {SPACE_SDK}")
52
+ print(f" Private : {PRIVATE}")
53
+ print()
54
+
55
+ # ── Get token securely ─────────────────────────────────────────
56
+ token = os.environ.get("HF_API_KEY") or os.environ.get("HF_TOKEN")
57
+ if not token:
58
+ print(" Enter your Hugging Face token (input is hidden):")
59
+ token = getpass.getpass(" HF Token > ").strip()
60
+
61
+ if not token or not token.startswith("hf_"):
62
+ print("[ERROR] Invalid token format. Must start with 'hf_'")
63
+ sys.exit(1)
64
+
65
+ # ── Authenticate ───────────────────────────────────────────────
66
+ print("\n[1/4] Authenticating with Hugging Face...")
67
+ try:
68
+ login(token=token, add_to_git_credential=False)
69
+ api = HfApi(token=token)
70
+ user = api.whoami()
71
+ print(f" βœ… Logged in as: {user['name']}")
72
+ except Exception as e:
73
+ print(f" ❌ Authentication failed: {e}")
74
+ sys.exit(1)
75
+
76
+ # ── Create or verify Space ─────────────────────────────────────
77
+ print(f"\n[2/4] Creating Space '{REPO_ID}' (skips if exists)...")
78
+ try:
79
+ url = create_repo(
80
+ repo_id=REPO_ID,
81
+ repo_type=REPO_TYPE,
82
+ space_sdk=SPACE_SDK,
83
+ private=PRIVATE,
84
+ token=token,
85
+ exist_ok=True,
86
+ )
87
+ print(f" βœ… Space ready: {url}")
88
+ except Exception as e:
89
+ print(f" ❌ Failed to create Space: {e}")
90
+ sys.exit(1)
91
+
92
+ # ── Upload folder ──────────────────────────────────────────────
93
+ print(f"\n[3/4] Uploading project files...")
94
+ print(f" Source: {PROJECT_DIR}")
95
+ try:
96
+ api.upload_folder(
97
+ folder_path=str(PROJECT_DIR),
98
+ repo_id=REPO_ID,
99
+ repo_type=REPO_TYPE,
100
+ token=token,
101
+ commit_message=COMMIT_MSG,
102
+ ignore_patterns=EXCLUDE_PATTERNS,
103
+ )
104
+ print(" βœ… All files uploaded successfully!")
105
+ except Exception as e:
106
+ print(f" ❌ Upload failed: {e}")
107
+ sys.exit(1)
108
+
109
+ # ── Done ───────────────────────────────────────────────────────
110
+ print(f"\n[4/4] Done!")
111
+ print(f"\n πŸš€ Your Space is live at:")
112
+ print(f" https://huggingface.co/spaces/{REPO_ID}")
113
+ print(f"\n πŸ“– API docs will be at:")
114
+ print(f" https://huggingface.co/spaces/{REPO_ID} β†’ /docs")
115
+ print()
116
+
117
+
118
+ if __name__ == "__main__":
119
+ main()