File size: 1,351 Bytes
6316722
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e317cf2
6316722
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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}")