Linzhan commited on
Commit
dd4d894
·
verified ·
1 Parent(s): c8d2710

Add tabular index (metadata.csv, characters.csv) + card metadata

Browse files
Files changed (1) hide show
  1. scripts/build_tables.py +44 -0
scripts/build_tables.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Generate ../metadata.csv (animations) and ../characters.csv from the JSON indexes.
3
+ Plain stdlib csv, so prompts containing commas/slashes are quoted correctly."""
4
+ import csv, json, os, sys
5
+ HERE=os.path.dirname(os.path.abspath(__file__)); ROOT=os.path.dirname(HERE)
6
+ J=lambda n: json.load(open(os.path.join(ROOT,n)))
7
+
8
+ prompts, frames = J("animation_prompts.json"), J("animation_frames.json")
9
+ rows=[]
10
+ for f in sorted(prompts):
11
+ v=prompts[f]
12
+ rows.append({
13
+ "file": "animation/"+f,
14
+ "prompt": v.get("prompt",""),
15
+ "description": v.get("description",""),
16
+ "text": v.get("description") or v.get("prompt",""), # ready-to-use label
17
+ "frames": frames.get(f,""),
18
+ "motion_id": v.get("motion_id",""),
19
+ })
20
+ out=os.path.join(ROOT,"metadata.csv")
21
+ with open(out,"w",newline="",encoding="utf-8") as fh:
22
+ w=csv.DictWriter(fh,fieldnames=["file","prompt","description","text","frames","motion_id"])
23
+ w.writeheader(); w.writerows(rows)
24
+ print("metadata.csv ->",len(rows),"rows")
25
+
26
+ chars, cbones = J("characters.json"), J("character_bones.json")
27
+ anim=set(J("animation_bones.json")["mixamo"])
28
+ crows=[]
29
+ for f in sorted(chars):
30
+ b=set(cbones.get(f,[]))
31
+ crows.append({
32
+ "file": "character_refined/"+f,
33
+ "file_original": "character/"+f,
34
+ "name": chars[f].get("name",""),
35
+ "uuid": chars[f].get("uuid",""),
36
+ "bone_count": len(b),
37
+ "covers_animation_rig": str(anim <= b).lower(),
38
+ })
39
+ out=os.path.join(ROOT,"characters.csv")
40
+ with open(out,"w",newline="",encoding="utf-8") as fh:
41
+ w=csv.DictWriter(fh,fieldnames=["file","file_original","name","uuid","bone_count","covers_animation_rig"])
42
+ w.writeheader(); w.writerows(crows)
43
+ n=sum(1 for r in crows if r["covers_animation_rig"]=="true")
44
+ print("characters.csv ->",len(crows),"rows |",n,"fully retargetable")