Qalam commited on
Commit
6325566
·
verified ·
1 Parent(s): 39f3162

Upload upload_to_hf.py

Browse files
Files changed (1) hide show
  1. upload_to_hf.py +94 -33
upload_to_hf.py CHANGED
@@ -1,47 +1,108 @@
1
  #!/usr/bin/env python3
2
  """
3
- AIQalam HuggingFace Uploader
4
- راهنما: توکن HuggingFace خودت رو جایگزین HF_TOKEN کن و اسکریپت رو اجرا کن
5
  """
6
 
7
  import os
8
-
9
- # توکن HuggingFace — از huggingface.co/settings/tokens بگیر
10
- HF_TOKEN = "YOUR_HF_TOKEN_HERE"
11
- REPO_ID = "Qalam/AIQalam"
12
-
13
- files_to_upload = [
14
- "AIQalam_agent.json",
15
- "AIQalam_agent_config.md",
16
- ]
17
-
18
- if HF_TOKEN == "YOUR_HF_TOKEN_HERE":
19
- print("⚠️ لطفاً HF_TOKEN رو در خط 8 اسکریپت وارد کن!")
20
- exit(1)
21
 
22
  try:
23
- from huggingface_hub import HfApi
24
  except ImportError:
25
- print("نصب huggingface_hub...")
26
  os.system("pip install huggingface_hub")
27
- from huggingface_hub import HfApi
28
 
29
- api = HfApi(token=HF_TOKEN)
30
 
31
- print(f"📤 آپلود به {REPO_ID}...")
 
 
 
 
 
32
 
33
- for fname in files_to_upload:
34
- if os.path.exists(fname):
35
- print(f" ⬆️ {fname}")
36
- api.upload_file(
37
- path_or_fileobj=fname,
38
- path_in_repo=fname,
39
- repo_id=REPO_ID,
40
- repo_type="space",
41
- )
42
- print(f" ✅ {fname} آپلود شد!")
 
43
  else:
44
- print(f" ⚠️ {fname} پیدا نشد!")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
 
46
- print("\n🎉 همه فایل‌ها آپلود شدند!")
47
- print(f"🔗 https://huggingface.co/{REPO_ID}")
 
1
  #!/usr/bin/env python3
2
  """
3
+ Qalam HuggingFace Upload Script
4
+ Upload Qalam agent configuration to HuggingFace Hub
5
  """
6
 
7
  import os
8
+ import argparse
9
+ from pathlib import Path
 
 
 
 
 
 
 
 
 
 
 
10
 
11
  try:
12
+ from huggingface_hub import HfApi, login
13
  except ImportError:
14
+ print("Installing huggingface_hub...")
15
  os.system("pip install huggingface_hub")
16
+ from huggingface_hub import HfApi, login
17
 
 
18
 
19
+ def get_token():
20
+ """Get token from environment or user input"""
21
+ token = os.environ.get("HF_TOKEN")
22
+ if not token:
23
+ token = input("Enter your HuggingFace token: ").strip()
24
+ return token
25
 
26
+
27
+ def upload_to_hf(token: str, repo_id: str = "Qalam/AIQalam", local_dir: str = None):
28
+ """Upload Qalam files to HuggingFace"""
29
+
30
+ api = HfApi()
31
+
32
+ print("Logging in to HuggingFace...")
33
+ login(token=token)
34
+
35
+ if local_dir is None:
36
+ local_dir = Path(__file__).parent.absolute()
37
  else:
38
+ local_dir = Path(local_dir).absolute()
39
+
40
+ print(f"Local directory: {local_dir}")
41
+
42
+ files_to_upload = [
43
+ "README.md",
44
+ "Qalam_agent_v3.json",
45
+ "Qalam_agent_v2.json",
46
+ "Qalam_agent.json",
47
+ "Qalam_Al-Mutlaq.json",
48
+ "Qalam_agent_config.md",
49
+ "upload_to_hf.py",
50
+ ]
51
+
52
+ existing_files = []
53
+ for f in files_to_upload:
54
+ path = local_dir / f
55
+ if path.exists():
56
+ existing_files.append(str(path))
57
+ print(f" Found: {f}")
58
+
59
+ if not existing_files:
60
+ print("No files found to upload!")
61
+ return
62
+
63
+ print(f"\nUploading {len(existing_files)} files to https://huggingface.co/{repo_id}")
64
+
65
+ try:
66
+ api.create_repo(
67
+ repo_id=repo_id,
68
+ repo_type="model",
69
+ exist_ok=True,
70
+ private=False
71
+ )
72
+ print(f"Repository ready: {repo_id}")
73
+ except Exception as e:
74
+ print(f"Error: {e}")
75
+ return
76
+
77
+ for file_path in existing_files:
78
+ file_name = Path(file_path).name
79
+ print(f" Uploading {file_name}...")
80
+ try:
81
+ api.upload_file(
82
+ path_or_fileobj=file_path,
83
+ path_in_repo=file_name,
84
+ repo_id=repo_id,
85
+ repo_type="model",
86
+ commit_message=f"Upload {file_name}"
87
+ )
88
+ print(f" Done: {file_name}")
89
+ except Exception as e:
90
+ print(f" Error uploading {file_name}: {e}")
91
+
92
+ print(f"\nDone! View at: https://huggingface.co/{repo_id}")
93
+
94
+
95
+ def main():
96
+ parser = argparse.ArgumentParser(description="Upload Qalam to HuggingFace")
97
+ parser.add_argument("--token", "-t", help="HuggingFace token (or set HF_TOKEN env var)")
98
+ parser.add_argument("--repo", "-r", default="Qalam/AIQalam", help="Repository ID")
99
+ parser.add_argument("--dir", "-d", help="Local directory")
100
+
101
+ args = parser.parse_args()
102
+
103
+ token = args.token or get_token()
104
+ upload_to_hf(token, args.repo, args.dir)
105
+
106
 
107
+ if __name__ == "__main__":
108
+ main()