Download code/scripts/daily.py from MiniMaxAI/oss-ecosystem-data: direct link, hf CLI and curl.
- Browser
- Download file 3.15 kB
-
https://huggingface.co/datasets/MiniMaxAI/oss-ecosystem-data/resolve/142f5d83f4ddb0789d0b654acf3105cc15e44ef0/code/scripts/daily.py
- Command line
-
hf download hf://datasets/MiniMaxAI/oss-ecosystem-data@142f5d83f4ddb0789d0b654acf3105cc15e44ef0/code/scripts/daily.py
-
curl -L -o daily.py https://huggingface.co/datasets/MiniMaxAI/oss-ecosystem-data/resolve/142f5d83f4ddb0789d0b654acf3105cc15e44ef0/code/scripts/daily.py
3.15 kB
| """Daily job: snapshot -> probe new/changed repos -> classify -> dashboard data -> push. | |
| python scripts/daily.py [--family h3 ...] [--push] [--skip-snapshot] | |
| Runs the same way locally and on HF Jobs. With --push it first mirrors the dataset repo, | |
| stores each family's raw snapshot before anything else (the one step that cannot be | |
| redone later), then pushes labels, the probe cache and the dashboard data. | |
| HF_TOKEN must be able to write the dataset repo and the Space repo. | |
| """ | |
| import argparse | |
| import json | |
| import sys | |
| import time | |
| from pathlib import Path | |
| import pandas as pd | |
| ROOT = Path(__file__).resolve().parent.parent | |
| sys.path.insert(0, str(ROOT)) | |
| from hfeco import authors, classify, discover, families, metrics, pipeline, store # noqa: E402 | |
| from hfeco.hub import api # noqa: E402 | |
| SPACE_REPO = "MiniMaxAI/oss-ecosystem" | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("--family", nargs="*", default=list(families.FAMILIES)) | |
| ap.add_argument("--push", action="store_true") | |
| ap.add_argument("--skip-snapshot", action="store_true") | |
| args = ap.parse_args() | |
| t0 = time.time() | |
| def log(m): | |
| print(f"[{time.time() - t0:6.0f}s] {m}", flush=True) | |
| if args.push: | |
| log("pull dataset") | |
| store.pull() | |
| for key in args.family: | |
| fam = families.get(key) | |
| log(f"== {fam.title}") | |
| if not args.skip_snapshot: | |
| raw_path = store.write_raw(discover.discover(fam, log=log), fam.key) | |
| if args.push: | |
| store.push([raw_path], f"{fam.key}: snapshot {raw_path.stem}") | |
| raw = store.read_raw(fam.key) | |
| today = raw[raw.day == raw.day.max()] | |
| cache, cache_path = pipeline.enrich_all(today, fam, log=log) | |
| labels = classify.classify_all(today, cache, fam) | |
| lab_path = store.LOCAL / "labels" / fam.key / "latest.parquet" | |
| lab_path.parent.mkdir(parents=True, exist_ok=True) | |
| ldf = pd.DataFrame(labels) | |
| for c in ("evidence", "flags"): | |
| ldf[c] = ldf[c].apply(lambda v: json.dumps(v, ensure_ascii=False)) | |
| ldf.to_parquet(lab_path, index=False) | |
| fam_ids = [x["repo_id"] for x in labels if x.get("family") and x["kind"] == "model"] | |
| who, who_path = authors.update({i.split("/")[0] for i in fam_ids} | {b.split("/")[0] for b in fam.bases}, log=log) | |
| data = metrics.build(raw, labels, metrics.hf_tree_counts(today, fam), fam, who) | |
| data_path = store.LOCAL / "dashboard" / f"{fam.key}.json" | |
| metrics.dump(data, data_path) | |
| log(f"{fam.key}: {len(labels)} labels, {len(data['repos'])} repos on the dashboard") | |
| if args.push: | |
| store.push([lab_path, cache_path, who_path], f"{fam.key}: labels {data['today']}") | |
| api.upload_file(path_or_fileobj=str(data_path), path_in_repo=f"data/{fam.key}.json", | |
| repo_id=SPACE_REPO, repo_type="space", commit_message=f"{fam.key}: data {data['today']}") | |
| idx_path = store.LOCAL / "dashboard" / "index.json" | |
| metrics.dump({"families": [{"key": f.key, "title": f.title} for f in families.FAMILIES.values()]}, idx_path) | |
| if args.push: | |
| api.upload_file(path_or_fileobj=str(idx_path), path_in_repo="data/index.json", repo_id=SPACE_REPO, | |
| repo_type="space", commit_message="index") | |
| log("pushed") | |