From 6a550d58473426e96e508978405dafeb19fc4c2b Mon Sep 17 00:00:00 2001 From: Jimmy Date: Tue, 13 Dec 2022 21:23:21 +1300 Subject: [PATCH] Example client --- imageserver/client.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 imageserver/client.py diff --git a/imageserver/client.py b/imageserver/client.py new file mode 100644 index 0000000..92f2f2a --- /dev/null +++ b/imageserver/client.py @@ -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() + + +