convert skimage to PIL image to bytes, post it
import skimage
import PIL
import requests
import io
image_sk_gray = skimage.io.imread(
image_path,
as_gray=True
)
image_binary = io.BytesIO()
image_pil = PIL.Image.fromarray(
skimage.img_as_ubyte(image_sk_gray)
)
image_pil.save(image_binary, format='PNG')
res = requests.post(
url_image_server,
files={"file": image_binary.getvalue()}
)
Another example
import io
image_extention = params['image_extention'] if 'jpg' in params.keys() else 'jpg'
image_quality = params['image_quality'] if 'image_quality' in params.keys() else 100
file_in_memory = io.BytesIO()
image.save(file_in_memory, image_extention, quality=image_quality)
file_in_memory.seek(0)
requests.post(
url=config.producer_url,
files=dict(
image=(f"{params['prompt']}.{image_extention}", params['prompt'], f'image/{image_extention}')
),
params={'task_id': task_id}
)