ai-image-forensics / scripts /deploy_to_hf.py
Nas0x1's picture
Deploy AI image forensics Space
f70b6e3 verified
Raw
History Blame Contribute Delete
1.48 kB
from __future__ import annotations
import os
from pathlib import Path
from huggingface_hub import HfApi
def main() -> None:
token = os.getenv("HF_TOKEN")
space_id = os.getenv("HF_SPACE_ID")
if not token:
raise SystemExit("Set HF_TOKEN to a Hugging Face write token.")
if not space_id or "/" not in space_id:
raise SystemExit("Set HF_SPACE_ID, for example: your-username/ai-image-forensics")
root = Path(__file__).resolve().parents[1]
api = HfApi(token=token)
api.create_repo(
repo_id=space_id,
repo_type="space",
space_sdk="gradio",
exist_ok=True,
private=os.getenv("HF_SPACE_PRIVATE", "0").lower() in {"1", "true", "yes"},
)
commit = api.upload_folder(
repo_id=space_id,
repo_type="space",
folder_path=root,
commit_message="Deploy AI image forensics Space",
ignore_patterns=[
".git/*",
"__pycache__/*",
"**/__pycache__/*",
"*.pyc",
".env*",
".venv/*",
"venv/*",
".cache/*",
"hf_cache/*",
"models/*",
"checkpoints/*",
"*.ckpt",
"*.pt",
"*.pth",
"*.onnx",
"*.bin",
"*.safetensors",
],
)
print(f"Uploaded to https://huggingface.co/spaces/{space_id}")
print(f"Commit: {commit.oid}")
if __name__ == "__main__":
main()