我正在编写一个telegram 机器人,它将使用这个稳定的扩散模型生成图像:https://replicate.com/mbentley124/openjourney-img2img
我正在使用复制模块.但是,当有人发送请求时,下面的代码片段会降低机器人的运行速度.
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])
请帮助使此代码异步,这是可取的添加一个队列.