From 198a1ffcfc963a3d74674fad560e87dbebf7949f Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Tue, 1 Nov 2022 19:13:59 +0300 Subject: [PATCH] fix API returning extra stuff in base64 encoded iamges for #3972 --- modules/api/api.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/api/api.py b/modules/api/api.py index e702c9c0f..bb87d795a 100644 --- a/modules/api/api.py +++ b/modules/api/api.py @@ -1,6 +1,8 @@ +import base64 +import io import time import uvicorn -from gradio.processing_utils import encode_pil_to_base64, decode_base64_to_file, decode_base64_to_image +from gradio.processing_utils import decode_base64_to_file, decode_base64_to_image from fastapi import APIRouter, Depends, HTTPException import modules.shared as shared from modules import devices @@ -29,6 +31,12 @@ def setUpscalers(req: dict): return reqDict +def encode_pil_to_base64(image): + buffer = io.BytesIO() + image.save(buffer, format="png") + return base64.b64encode(buffer.getvalue()) + + class Api: def __init__(self, app, queue_lock): self.router = APIRouter()