| |
|
| | import csv |
| | import os |
| |
|
| | format_map = { |
| | "zh": "十六进制代码", |
| | "fr": "code hexadécimal", |
| | "en": "Hex code" |
| | } |
| |
|
| |
|
| | def merge_prompt_with_colors(prompt_file, color_file, output_file, variation=1, color_level=1): |
| | format_map = { |
| | "zh": "十六进制代码", |
| | "fr": "code hexadécimal", |
| | "en": "Hex code" |
| | } |
| |
|
| | |
| | with open(prompt_file, "r", encoding="utf-8") as f: |
| | reader = csv.DictReader(f) |
| | prompts = list(reader) |
| |
|
| | |
| | with open(color_file, "r", encoding="utf-8") as f: |
| | reader = csv.DictReader(f) |
| | colors = list(reader) |
| |
|
| | merged_rows = [] |
| | id_counter = 1 |
| | for prompt in prompts: |
| | prompt_text = prompt["prompt"] |
| | lang_val = prompt.get("lang", "en").lower() |
| | localized_format = format_map.get(lang_val, "Hex code") |
| |
|
| | for color in colors: |
| | hex_val = color.get("hex") or color.get("color") or "" |
| | split_val = "test" |
| |
|
| | merged_rows.append({ |
| | "id": id_counter, |
| | "prompt": prompt_text, |
| | "color_1": hex_val, |
| | "variation": variation, |
| | "color_level": color_level, |
| | "split": split_val, |
| | "color_format": localized_format, |
| | "lang": lang_val |
| | }) |
| | id_counter += 1 |
| |
|
| | fieldnames = ["id", "prompt", "color_1", "variation", "color_level", "split", "color_format", "lang"] |
| |
|
| | |
| | output_dir = os.path.dirname(output_file) |
| | if output_dir and not os.path.exists(output_dir): |
| | os.makedirs(output_dir, exist_ok=True) |
| |
|
| | |
| | with open(output_file, "w", newline="", encoding="utf-8") as f: |
| | writer = csv.DictWriter(f, fieldnames=fieldnames) |
| | writer.writeheader() |
| | writer.writerows(merged_rows) |
| |
|
| | print(f"Generation complete: {output_file} (Contain {id_counter-1} data entries).") |
| |
|
| |
|
| | merge_prompt_with_colors("raw_config/Variation_5.csv", "raw_config/Color_Level_1.csv", "metadata/Variation_5_Color_1.csv", variation=5, color_level=1) |
| | merge_prompt_with_colors("raw_config/Variation_5.csv", "raw_config/Color_Level_2.csv", "metadata/Variation_5_Color_2.csv", variation=5, color_level=2) |
| | merge_prompt_with_colors("raw_config/Variation_5.csv", "raw_config/Color_Level_3.csv", "metadata/Variation_5_Color_3.csv", variation=5, color_level=3) |
| |
|
| |
|