from src.image_gen import image_style, replicate_flux_schnell_image_gen, Styles, save_image_url, \
    replicate_flux_1_1_pro_image_gen
from src.llm_description_gen import describe_noun_llama_3_8b, describe_noun_llama_3_70b
from pathlib import Path


if __name__ == "__main__":
    with open("./data/imageable_deduplicate.txt", "r") as fp:
        nouns = fp.read().split("\n")

    for i in range(100):
        noun = nouns[i]
        print(f"image {noun} {i}")
        description = describe_noun_llama_3_70b(noun)
        content = description.lower()
        if "invalid" in content:
            continue

        output_dir = Path(f"./output/test9/flux_1_1_pro/{noun}")
        content = image_style(content, Styles.cartoon)
        try:
            image_url = replicate_flux_1_1_pro_image_gen(content)
        except Exception as e:
            print(f"error: {str(e)} for content: {content}")
            continue

        save_image_url(image_url, output_dir)
        with open(Path(output_dir) / "description.txt", "w") as fp:
            fp.write(content)
