-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdalle.py
More file actions
41 lines (32 loc) · 1.14 KB
/
dalle.py
File metadata and controls
41 lines (32 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import base64
from PIL import Image
import asyncio
import aiohttp
import json
import io
url = "http://127.0.0.1:8080/dalle"
def get_concat_h():
images = [Image.open(x) for x in ['0.png', '1.png', '2.png', '3.png']]
widths, heights = zip(*(i.size for i in images))
total_width = sum(widths)
max_height = max(heights)
new_im = Image.new('RGB', (total_width, max_height))
x_offset = 0
for im in images:
new_im.paste(im, (x_offset,0))
x_offset += im.size[0]
new_im.save('result.jpg')
async def asyncGetImgFromPrompt(num, prmpt):
reqJson = {"text" : prmpt, "num_images" : num }
req = json.dumps(reqJson)
async with aiohttp.ClientSession() as session:
async with session.post(url, data=req) as res:
images = await res.json()
for x in range(len(images)):
imgData = base64.b64decode(images[x])
buf = io.BytesIO(imgData)
img = Image.open(buf)
img.save("{}.png".format(x), format="png")
get_concat_h()
async def asyncDiscordEntry(num, prompt):
await asyncGetImgFromPrompt(num, prompt)