fix: imagine
black-action / runner / black formatter (push) Failing after -1s Details

This commit is contained in:
0xMRTT 2023-06-21 11:31:18 +02:00
parent 51f1edb28d
commit a9b9eee182
Signed by: 0xMRTT
GPG Key ID: 910B287304120902
1 changed files with 28 additions and 16 deletions

View File

@ -104,24 +104,36 @@ def run():
else:
prompt += arg + " "
imagine = Imagine()
filename = str(uuid.uuid4()) + ".png"
# style_enum = Style[style]
# ratio_enum = Ratio[ratio]
img_data = await imagine.sdprem(
prompt=prompt,
#style=style_enum,
#ratio=ratio_enum,
negative=negative,
)
try:
with open(filename, mode="wb") as img_file:
img_file.write(img_data)
except Exception as e:
print(f"An error occurred while writing the image to file: {e}")
return None
async def generate_image(image_prompt, style_value, ratio_value, negative):
if negative is None:
negative = False
imagine = Imagine()
filename = str(uuid.uuid4()) + ".png"
style_enum = Style[style_value]
ratio_enum = Ratio[ratio_value]
img_data = await imagine.sdprem(
prompt=image_prompt,
style=style_enum,
ratio=ratio_enum,
negative=negative
)
try:
with open(filename, mode="wb") as img_file:
img_file.write(img_data)
except Exception as e:
print(
f"An error occurred while creating the image file: {e}")
return None
await imagine.close()
return img_file
filename = await generate_image(prompt, style, ratio, negative)
await bot.api.send_image_message(
room_id=room.room_id, image_filepath=filename