Example client

This commit is contained in:
Jimmy 2022-12-13 21:23:21 +13:00
parent 7dba63c954
commit 6a550d5847
1 changed files with 40 additions and 0 deletions

40
imageserver/client.py Normal file
View File

@ -0,0 +1,40 @@
# import aiohttp
# import aiofiles
import asyncio
import requests
from io import BytesIO
from PIL import Image
import shutil
from random import randint
def main():
print("Starting")
img = Image.new('RGB', (25, 25), color = (randint(0, 255), randint(0, 255), randint(0, 255)))
img = Image.open("/home/jimmy/image.png")
byte_io = BytesIO()
img.save(byte_io, 'png')
byte_io.seek(0)
r = requests.post(url='http://localhost:8000?text=cartoon',
files={
'my_file': (
'1.png',
byte_io,
'image/png'
),
},
stream=True
)
print(r.status_code)
if r.status_code == 200:
byte_io = BytesIO(r.content)
img = Image.open(byte_io)
img.show()
if __name__ == '__main__':
main()