This commit is contained in:
parent
51f1edb28d
commit
a9b9eee182
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user