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

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

View File

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