| import os |
| import json |
| from tqdm import tqdm |
| import re |
|
|
| def build_final_metadata(): |
| base_data_dir = "data" |
| output_jsonl = os.path.join(base_data_dir, "metadata.jsonl") |
| |
| entries = [] |
| |
| |
| for var_idx in range(1, 7): |
| var_dir = os.path.join(base_data_dir, f"Variation_{var_idx}") |
| if not os.path.exists(var_dir): continue |
| |
| |
| for lvl_idx in range(1, 4): |
| lvl_dir = os.path.join(var_dir, f"Color_Level_{lvl_idx}") |
| if not os.path.exists(lvl_dir): continue |
| |
| |
| |
| |
| files = [f for f in os.listdir(lvl_dir) if f.endswith(".png")] |
|
|
| |
| files.sort(key=lambda f: int(re.search(r'\d+', f).group())) |
| |
| for f in tqdm(files): |
| id_name = f.replace(".png", "") |
| txt_file = os.path.join(lvl_dir, f"{id_name}.txt") |
| |
| |
| prompt_content = "" |
| if os.path.exists(txt_file): |
| with open(txt_file, "r", encoding="utf-8") as tf: |
| prompt_content = tf.read().strip() |
| |
| rel_path = f"Variation_{var_idx}/Color_Level_{lvl_idx}/{f}" |
| |
| entries.append({ |
| "file_name": rel_path, |
| "text": prompt_content, |
| "variation": var_idx, |
| "color_level": lvl_idx, |
| "id": id_name, |
| "split": "test" |
| }) |
|
|
| with open(output_jsonl, "w", encoding="utf-8") as out: |
| for entry in entries: |
| out.write(json.dumps(entry, ensure_ascii=False) + "\n") |
|
|
| print(f"total {len(entries)} entries in {output_jsonl}") |
|
|
| if __name__ == "__main__": |
| build_final_metadata() |