| | import csv |
| | import random |
| | import os |
| |
|
| | def merge_prompt_with_two_colors(prompt_file, color_file, output_file, variation=2, color_level=2): |
| | |
| | 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"] |
| |
|
| | |
| | lower_text = prompt_text.lower() |
| | |
| | if any(word in lower_text for word in ["upper", "lower", "top", "bottom"]): |
| | direction = "h" |
| | |
| | elif any(word in lower_text for word in ["left", "right"]): |
| | direction = "v" |
| | |
| | else: |
| | |
| | direction = "u" |
| |
|
| | |
| | for color1 in colors: |
| | hex1 = color1.get("hex") or color1.get("color") or "" |
| |
|
| | |
| | color2_choices = random.sample(colors, 2) |
| |
|
| | for color2 in color2_choices: |
| | hex2 = color2.get("hex") or color2.get("color") or "" |
| |
|
| | merged_rows.append({ |
| | "id": id_counter, |
| | "prompt": prompt_text, |
| | "direction": direction, |
| | "color_1": hex1, |
| | "color_2": hex2, |
| | "variation": variation, |
| | "color_level": color_level, |
| | "split": "test", |
| | "color_format": "Hex code", |
| | }) |
| | id_counter += 1 |
| |
|
| | |
| | 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=["id","prompt","direction","color_1","color_2","variation","color_level","split","color_format"]) |
| | writer.writeheader() |
| | writer.writerows(merged_rows) |
| |
|
| | print(f"Generation complete: {output_file}") |
| |
|
| |
|
| | random.seed(42) |
| | merge_prompt_with_two_colors("raw_config/Variation_2.csv", "raw_config/Color_Level_1.csv", "metadata/Variation_2_Color_1.csv", variation=2, color_level=1) |
| | merge_prompt_with_two_colors("raw_config/Variation_2.csv", "raw_config/Color_Level_2.csv", "metadata/Variation_2_Color_2.csv", variation=2, color_level=2) |
| | merge_prompt_with_two_colors("raw_config/Variation_2.csv", "raw_config/Color_Level_3.csv", "metadata/Variation_2_Color_3.csv", variation=2, color_level=3) |
| |
|