Spaces:
Sleeping
Sleeping
File size: 1,686 Bytes
09fe9bc c4376df 09fe9bc c4376df 09fe9bc c4376df 09fe9bc c4376df 09fe9bc c4376df 09fe9bc | 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 | """Derive users.json from per-persona memory JSONs in memories/.
The memory JSONs are the source of truth for each persona's structured profile.
This script reads every memories/*.json and projects a thin index entry into
users.json for the frontend PersonaSelector and for session lookup.
Run after editing any persona JSON:
cd data && python generate_users.py
"""
import json
from pathlib import Path
def main() -> None:
memories_dir = Path("memories")
if not memories_dir.is_dir():
raise SystemExit(f"Expected directory not found: {memories_dir.resolve()}")
user_index: list[dict] = []
for path in sorted(memories_dir.glob("*.json")):
with open(path) as f:
persona = json.load(f)
profile = persona["profile"]
prefs = profile.get("stylistic_preferences") or {}
access = (profile.get("access_needs") or {}).get("input_method")
tone_summary = ", ".join(prefs.get("tone", []))
user_index.append(
{
"id": profile["id"],
"name": profile["name"],
"age": profile.get("age"),
"condition": profile["condition"],
"access_method": access,
"tone_summary": tone_summary,
"file": f"memories/{profile['id']}.json",
}
)
out_path = Path("users.json")
with open(out_path, "w") as f:
json.dump({"users": user_index}, f, indent=2, ensure_ascii=False)
print(f"Indexed {len(user_index)} personas → {out_path}")
for u in user_index:
print(f" {u['id']:25s} {u['name']:30s} {u['condition']}")
if __name__ == "__main__":
main()
|