feat: use dalle
Some checks failed
black-action / runner / black formatter (push) Failing after -1s

This commit is contained in:
0xMRTT 2023-06-21 10:55:45 +02:00
parent e72ffd6d8b
commit a88f6b3618
Signed by: 0xMRTT
GPG Key ID: 910B287304120902

View File

@ -751,8 +751,40 @@ def run():
await imagine.close()
return img_file
filename = await generate_image(prompt, style, ratio, negative, upscale=False)
async def generate_dalle_image(prompt, size):
base_urls = ['https://a.z-pt.com']
endpoint = '/api/openai/v1/images/generations'
headers = {
'Content-Type': 'application/json',
}
data = {
'prompt': prompt,
'n': 1,
'size': size
}
async with aiohttp.ClientSession() as session:
for base_url in base_urls:
url = base_url + endpoint
async with session.post(url, headers=headers, json=data) as response:
if response.status != 200:
continue
response_data = await response.json()
if 'error' in response_data:
return None
image_url = response_data['data'][0]['url']
async with session.get(image_url) as image_response:
image_content = await image_response.read()
img_file = io.BytesIO(image_content)
return img_file
return None
#filename = await generate_image(prompt, style, ratio, negative, upscale=False)
filename = await generate_dalle_image(prompt, 512)
await bot.api.send_image_message(
room_id=room.room_id, image_filepath=filename
)