Download engine_3_0/training_scripts/make_interest_taxonomy_ts.py from Tirthanker/UniHive_RecSys: direct link, hf CLI and curl.
- Browser
- Download file 1.66 kB
-
https://huggingface.co/Tirthanker/UniHive_RecSys/resolve/main/engine_3_0/training_scripts/make_interest_taxonomy_ts.py
- Command line
-
hf download hf://Tirthanker/UniHive_RecSys/engine_3_0/training_scripts/make_interest_taxonomy_ts.py
-
curl -L -o make_interest_taxonomy_ts.py https://huggingface.co/Tirthanker/UniHive_RecSys/resolve/main/engine_3_0/training_scripts/make_interest_taxonomy_ts.py
1.66 kB
| """Generate src/interestTaxonomy.ts (data only) for the UniHive frontend: the recommender's 13 interest categories and 114 interests. | |
| `slug` and `label` are exactly what migration 012 seeds into `domains`, and what POST /api/users/profile resolves (it matches interest strings against | |
| domains.name or domains.slug, case-insensitively), so the onboarding screen can send either. Usage: python make_interest_taxonomy_ts.py <taxonomy.py> <out.ts>""" | |
| import importlib.util, json, sys | |
| src, out = sys.argv[1], sys.argv[2] | |
| spec = importlib.util.spec_from_file_location("taxonomy", src); tx = importlib.util.module_from_spec(spec); spec.loader.exec_module(tx) | |
| cats = [{"slug": tx.slugify(n), "label": n, "description": d, "interests": [{"slug": tx.slugify(c), "label": c} for c in kids]} for b, n, d, kids in tx.TAXONOMY] | |
| assert len(cats) == 13 and sum(len(c["interests"]) for c in cats) == 114 | |
| ts = ("// Generated from the recommender's taxonomy (backend/migrations/012_domains_catalogue.sql seeds the same rows into `domains`).\n" | |
| "// Send either `slug` or `label` to POST /api/users/profile as an interest; the backend resolves it against domains.slug / domains.name.\n" | |
| "export interface InterestItem { slug: string; label: string }\n" | |
| "export interface InterestCategory { slug: string; label: string; description: string; interests: InterestItem[] }\n\n" | |
| f"export const INTEREST_TAXONOMY: InterestCategory[] = {json.dumps(cats, indent=2, ensure_ascii=False)}\n") | |
| open(out, "w", encoding="utf8", newline="\n").write(ts); print("written", out, "|", len(cats), "categories,", sum(len(c["interests"]) for c in cats), "interests") | |