File size: 2,007 Bytes
5e1ef3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
53
54
55
56
57
58
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
            
            #print(f"Processing Variation {var_idx}, Color_Level {lvl_idx}...")
            
            
            files = [f for f in os.listdir(lvl_dir) if f.endswith(".png")]

            # Use lambda to extract the numerical parts and sort them.
            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")
                
                # Read the corresponding txt content as a prompt
                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()