| |
| """ |
| Qalam HuggingFace Upload Script |
| Upload Qalam agent configuration to HuggingFace Hub |
| """ |
|
|
| import os |
| import argparse |
| from pathlib import Path |
|
|
| try: |
| from huggingface_hub import HfApi, login |
| except ImportError: |
| print("Installing huggingface_hub...") |
| os.system("pip install huggingface_hub") |
| from huggingface_hub import HfApi, login |
|
|
|
|
| def get_token(): |
| """Get token from environment or user input""" |
| token = os.environ.get("HF_TOKEN") |
| if not token: |
| token = input("Enter your HuggingFace token: ").strip() |
| return token |
|
|
|
|
| def upload_to_hf(token: str, repo_id: str = "Qalam/AIQalam", local_dir: str = None): |
| """Upload Qalam files to HuggingFace""" |
| |
| api = HfApi() |
| |
| print("Logging in to HuggingFace...") |
| login(token=token) |
| |
| if local_dir is None: |
| local_dir = Path(__file__).parent.absolute() |
| else: |
| local_dir = Path(local_dir).absolute() |
| |
| print(f"Local directory: {local_dir}") |
| |
| files_to_upload = [ |
| "README.md", |
| "Qalam_agent_v3.json", |
| "Qalam_agent_v2.json", |
| "Qalam_agent.json", |
| "Qalam_Al-Mutlaq.json", |
| "Qalam_agent_config.md", |
| "upload_to_hf.py", |
| ] |
| |
| existing_files = [] |
| for f in files_to_upload: |
| path = local_dir / f |
| if path.exists(): |
| existing_files.append(str(path)) |
| print(f" Found: {f}") |
| |
| if not existing_files: |
| print("No files found to upload!") |
| return |
| |
| print(f"\nUploading {len(existing_files)} files to https://huggingface.co/{repo_id}") |
| |
| try: |
| api.create_repo( |
| repo_id=repo_id, |
| repo_type="model", |
| exist_ok=True, |
| private=False |
| ) |
| print(f"Repository ready: {repo_id}") |
| except Exception as e: |
| print(f"Error: {e}") |
| return |
| |
| for file_path in existing_files: |
| file_name = Path(file_path).name |
| print(f" Uploading {file_name}...") |
| try: |
| api.upload_file( |
| path_or_fileobj=file_path, |
| path_in_repo=file_name, |
| repo_id=repo_id, |
| repo_type="model", |
| commit_message=f"Upload {file_name}" |
| ) |
| print(f" Done: {file_name}") |
| except Exception as e: |
| print(f" Error uploading {file_name}: {e}") |
| |
| print(f"\nDone! View at: https://huggingface.co/{repo_id}") |
|
|
|
|
| def main(): |
| parser = argparse.ArgumentParser(description="Upload Qalam to HuggingFace") |
| parser.add_argument("--token", "-t", help="HuggingFace token (or set HF_TOKEN env var)") |
| parser.add_argument("--repo", "-r", default="Qalam/AIQalam", help="Repository ID") |
| parser.add_argument("--dir", "-d", help="Local directory") |
| |
| args = parser.parse_args() |
| |
| token = args.token or get_token() |
| upload_to_hf(token, args.repo, args.dir) |
|
|
|
|
| if __name__ == "__main__": |
| main() |