I am writing a telegram bot that will generate images using this stable diffusion model: https://replicate.com/mbentley124/openjourney-img2img
I am using the replicate module. however, the code snippet below slows down the bot when someone sends a request.
async def txt2img(message, prompt, negative, stepMode, width, height):
print('Generating image for ' + str(message.chat.id))
output = replicate.run(
"tstramer/midjourney-diffusion:436b051ebd8f68d23e83d22de5e198e0995357afef113768c20f0b6fcef23c8b",
input={"prompt": "mdjrny-v4 " + prompt, "negative_prompt": negative, "num_inference_steps": stepMode*10, "width": width, "height": height}
)
print(output[0] + '\n')
return await message.answer_photo(output[0])
Please help to make this code asynchronous and it is desirable to add a queue.