File size: 1,912 Bytes
01a96a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Check the rendered HF eval.yaml page at an immutable revision, without a GPU.

Usage: uv run --no-project scripts/check_hub_metadata.py --revision main
This checks metadata validation, not benchmark allow-list activation.
"""
import argparse
import json
from html.parser import HTMLParser
from urllib.parse import quote
from urllib.request import urlopen


class VisibleText(HTMLParser):
    def __init__(self):
        super().__init__()
        self.parts = []
        self.hidden = 0

    def handle_starttag(self, tag, attrs):
        if tag in {"script", "style"}:
            self.hidden += 1

    def handle_endtag(self, tag):
        if tag in {"script", "style"}:
            self.hidden = max(0, self.hidden - 1)

    def handle_data(self, data):
        if not self.hidden:
            self.parts.append(data)


def main():
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--revision", default="main")
    args = parser.parse_args()
    repo = "d0rj/ROMB-1.0"
    with urlopen(
        f"https://huggingface.co/api/datasets/{repo}/revision/{quote(args.revision, safe='')}",
        timeout=30,
    ) as response:
        revision = json.load(response)["sha"]
    url = f"https://huggingface.co/datasets/{repo}/blob/{revision}/eval.yaml"
    with urlopen(url, timeout=30) as response:
        page = response.read().decode("utf-8")
    text = VisibleText()
    text.feed(page)
    visible = " ".join(" ".join(text.parts).split())
    if "eval.yaml" not in visible:
        raise SystemExit("Unexpected page: eval.yaml viewer was not found")
    if "YAML Metadata" in visible or "Invalid content in eval.yaml" in visible:
        raise SystemExit(f"HF metadata validation FAILED: {url}")
    print(f"HF metadata validation passed: {url}")
    print("This does not confirm benchmark activation or hosted custom-code support.")


if __name__ == "__main__":
    main()