File size: 2,842 Bytes
ebc0d9f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python3
"""Inspect Space settings, exact model inventories and authorized download access.

This does not change the Space, download tensor payloads or run model inference.
Authentication comes from HF_TOKEN or the local Hugging Face login cache.
"""
from __future__ import annotations

import argparse
import json
import os
from pathlib import Path
import sys

ROOT = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(ROOT))


def main() -> int:
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--space", default="UniLat3D/Supra-Tex")
    parser.add_argument("--repo", default="supra3d/supra-tex")
    parser.add_argument("--revision")
    parser.add_argument("--output", type=Path, default=ROOT / ".deployment-evidence/deployment-audit.json")
    args = parser.parse_args()

    # The desktop runtime and the user's terminal can have different cache roots.
    # Record only the cache path in local evidence; no token enters the repository.
    local_state = ROOT / ".deployment-evidence/deployment-state.json"
    if local_state.is_file() and not os.environ.get("HF_TOKEN"):
        cache = json.loads(local_state.read_text()).get("auth_cache")
        if cache:
            os.environ.setdefault("HF_HOME", cache)

    from huggingface_hub import HfApi, get_token
    from hf_space.audit import audit_sources
    from scripts.install_runtime import NATTEN_VERSION

    api = HfApi()
    account = api.whoami()["name"] if get_token() else None
    space = api.space_info(args.space)
    arguments = ["--repo", args.repo, "--with-rmbg"]
    if args.revision:
        arguments.extend(["--revision", args.revision])
    models = audit_sources(arguments)
    files = [item.rfilename for item in space.siblings]
    report = {
        "authenticated_account": account,
        "space": {"id": args.space, "commit": space.sha,
                  "configuration": space.card_data.to_dict() if space.card_data else {},
                  "runtime": space.runtime.raw, "files": files},
        "supplied_source_runtime": {"python": "3.10", "torch": "2.6.0+cu124",
                                    "natten": NATTEN_VERSION},
        "local_app_entrypoint_present": (ROOT / "app.py").is_file(),
        "remote_app_entrypoint_present": "app.py" in files,
        "models": models,
        "validation_limits": ["No tensor payloads downloaded", "Native CUDA builds not tested",
                              "ZeroGPU compatibility not established", "Full image-to-GLB inference not run"],
    }
    args.output.parent.mkdir(parents=True, exist_ok=True)
    args.output.write_text(json.dumps(report, indent=2) + "\n", encoding="utf-8")
    print(json.dumps(report, indent=2))
    return 0 if models["ok"] and "app.py" in files else 2


if __name__ == "__main__":
    raise SystemExit(main())