ai-kit / image_gen /image_generation.py
Kim Adams
adding batching to video transcription
e2e1045
from utilities import prompt_constants, constants
import openai
import pandas as pd
DALL_E_MAX_TOKENS=875
DALL_E_SIZE="512x512"
DALL_E_NUM_IMAGES=3
def AddArtStyle(artOptions):
print("AddArtStyle: "+artOptions.value)
if artOptions.value== constants.IMAGE_ART_2:
return prompt_constants.POP_ART_PROMPT
elif artOptions.value== constants.IMAGE_ART_3:
return prompt_constants.CUBISM_PROMPT
elif artOptions.value== constants.IMAGE_ART_4:
return prompt_constants.BAROQUE_PROMPT
elif artOptions.value== constants.IMAGE_ART_5:
return prompt_constants.PHOTOREALISTIC_PROMPT
elif artOptions.value== constants.IMAGE_ART_6:
return prompt_constants.CARTOON_PROMPT
elif artOptions.value== constants.IMAGE_ART_7:
return prompt_constants.SURREALISM_PROMPT
elif artOptions.value== constants.IMAGE_ART_8:
return prompt_constants.POINTALISM_PROMPT
elif artOptions.value== constants.IMAGE_ART_9:
return prompt_constants.BLUE_PRINT_PROMPT
elif artOptions.value== constants.IMAGE_ART_10:
return prompt_constants.LINE_ART_PROMPT
else:
return prompt_constants.IMPRESSIONISM_PROMPT
def AddArtSetting(settingOptions):
print("AddArtSetting: "+settingOptions.value)
if settingOptions.value== constants.IMAGE_SETTING_2:
return prompt_constants.HISTORICAL_PROMPT
elif settingOptions.value== constants.IMAGE_SETTING_3:
return prompt_constants.PORTRAIT_PROMPT
elif settingOptions.value== constants.IMAGE_SETTING_4:
return prompt_constants.HIGH_FASHION_PROMPT
elif settingOptions.value== constants.IMAGE_SETTING_5:
return prompt_constants.ABSTRACT_PROMPT
elif settingOptions.value== constants.IMAGE_SETTING_6:
return prompt_constants.TRAVEL_AND_ADVENTURE_PROMPT
elif settingOptions.value== constants.IMAGE_SETTING_7:
return prompt_constants.STEAMPUNK_PROMPT
elif settingOptions.value== constants.IMAGE_SETTING_8:
return prompt_constants.SCI_FI_PROMPT
elif settingOptions.value== constants.IMAGE_SETTING_9:
return prompt_constants.LANDSCAPE_PROMPT
elif settingOptions.value== constants.IMAGE_SETTING_10:
return prompt_constants.WILDLIFE_PROMPT
else:
return prompt_constants.STILL_LIFE_PROMPT
def Completion(summary_messages, max_tokens=DALL_E_MAX_TOKENS):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=summary_messages
)
return response["choices"][0]["message"]["content"]
def ImageCompletion(prompt, imageNumber=DALL_E_NUM_IMAGES, size=DALL_E_SIZE):
response = openai.Image.create(
prompt=prompt,
n=DALL_E_NUM_IMAGES,
size=DALL_E_SIZE
)
return response['data'][0]['url'], response['data'][1]['url'],response['data'][2]['url']
def GenerateImages(imageDescription, artOptions, settingOptions):
system_text = f"{prompt_constants.IMAGE_PROMPT_PREFIX} {AddArtStyle(artOptions)} {AddArtSetting(settingOptions)}"
user_text = f"{imageDescription}"
imgMessages = []
imgMessages.append({"role": "user", "content": " Subject: " + user_text})
imgMessages.append({"role": "system", "content":system_text})
response_message = Completion(imgMessages)
imgMessages.append({"role": "assistant", "content": response_message})
truncated_prompt= response_message[:999]
imgMessages.append({"role": "image", "content": truncated_prompt})
df = pd.DataFrame(imgMessages)
img1, img2, img3 = ImageCompletion(truncated_prompt, DALL_E_NUM_IMAGES, DALL_E_SIZE)
return img1, img2, img3, df