| from pathlib import Path | |
| import os | |
| from huggingface_hub import HfApi | |
| api = HfApi() | |
| # Replace with your desired repo name, e.g., "username/ai-detector-v1" | |
| repo_id = "DaJulster/SuaveAI-Dectection-Multitask-Model-V1" | |
| required_files = [ | |
| "multitask_model.pth", | |
| "label_encoder.pkl", | |
| "README.md", | |
| ] | |
| missing = [file_name for file_name in required_files if not Path(file_name).exists()] | |
| if missing: | |
| raise FileNotFoundError(f"Missing required files: {', '.join(missing)}") | |
| # 1. Create the repository on the Hub (if it doesn't exist) | |
| api.create_repo(repo_id=repo_id, repo_type="model", exist_ok=True) | |
| # 2. Generate HF-compatible artifacts from existing checkpoint (optional) | |
| skip_prepare = os.environ.get("SKIP_HF_PREPARE", "0") == "1" | |
| if not skip_prepare: | |
| from prepare_hf_artifacts_light import main as prepare_hf_artifacts | |
| prepare_hf_artifacts() | |
| else: | |
| print("Skipping HF artifact generation (SKIP_HF_PREPARE=1)") | |
| # 3. Upload all local artifacts (model card + model files) | |
| api.upload_folder( | |
| folder_path=".", | |
| repo_id=repo_id, | |
| repo_type="model", | |
| ignore_patterns=[ | |
| "*.pyc", | |
| "__pycache__/*", | |
| ".git/*", | |
| "*.ipynb", | |
| "venv/*", | |
| "tok.txt", | |
| ], | |
| ) | |
| print(f"Model pushed successfully to: https://huggingface.co/{repo_id}") |