From e35f549a09512618b7003867f320e2078b13acf2 Mon Sep 17 00:00:00 2001 From: Parish Wolfe Date: Wed, 25 Sep 2024 17:33:32 -0400 Subject: [PATCH] Changes from testing --- product_pipeline.py | 21 +++++++++++++++------ res/models/tshirt.py | 4 ++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/product_pipeline.py b/product_pipeline.py index aad51aa..4185213 100644 --- a/product_pipeline.py +++ b/product_pipeline.py @@ -3,12 +3,13 @@ import argparse import uuid import random +import json from datetime import datetime from util.printify_util import printify_util from util.ai_util import ai_util from util.image_util import create_text_image -from res.models.tshirt import tshirt_from_ai, basic_tshirt_product +from res.models.tshirt import tshirt_from_ai, tshirt_from_ai_list from dotenv import load_dotenv @@ -47,18 +48,26 @@ def main(): response = ai.chat( messages = prompt, - output_model=tshirt_from_ai + output_model=tshirt_from_ai_list, ) - for pattern in response.patterns: + # Parse the response + print(response) + print(type(response)) + parsed_response = json.loads(response) + patterns = parsed_response['patterns'] + + + + for pattern in patterns: print(pattern) #[{pattern.title, pattern.description, pattern.tshirt_text}] # generate filename - filename = uuid.uuid5(uuid.NAMESPACE_DNS, random.getrandombits(128)) + #filename = uuid.uuid5(uuid.NAMESPACE_DNS, random.getrandbits(128)) #TODO - broken # generate image create_text_image( - text=imagepattern.tshirt_text, + text=pattern.get("tshirt_text"), height=1000, width=1000, - file_name=filename + file_name=pattern.get("title"), color="#000000" ) #TOOD = make both white text and black text version of this # upload the image diff --git a/res/models/tshirt.py b/res/models/tshirt.py index 1cdcf04..f8a1ecf 100644 --- a/res/models/tshirt.py +++ b/res/models/tshirt.py @@ -7,6 +7,10 @@ class tshirt_from_ai(BaseModel): # tshirt_text is the text that will be printed on the tshirt tshirt_text: str +class tshirt_from_ai_list(BaseModel): + """A pydantic model for a list of ai generated fields""" + patterns: list[tshirt_from_ai] + class basic_tshirt_product(BaseModel): title: str