diff options
author | KyuSeok Jung <wjdrbtjr495@gmail.com> | 2022-11-02 08:10:56 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-02 08:10:56 +0000 |
commit | af6fba247553e670ef5e2dcc1866279f9f065d6d (patch) | |
tree | 160b205b1c11025b0195c3857c8a73cccc0c80c5 /modules/api/api.py | |
parent | 467cae167a3066ffa2b2a5e6f16dd42642219aba (diff) | |
parent | 95c6308ccd2e075d1fb804f5b98a4f0b07b87b7d (diff) | |
download | stable-diffusion-webui-gfx803-af6fba247553e670ef5e2dcc1866279f9f065d6d.tar.gz stable-diffusion-webui-gfx803-af6fba247553e670ef5e2dcc1866279f9f065d6d.tar.bz2 stable-diffusion-webui-gfx803-af6fba247553e670ef5e2dcc1866279f9f065d6d.zip |
Merge branch 'master' into master
Diffstat (limited to 'modules/api/api.py')
-rw-r--r-- | modules/api/api.py | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/modules/api/api.py b/modules/api/api.py index 6c06d449..bb87d795 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() @@ -40,6 +48,7 @@ class Api: self.app.add_api_route("/sdapi/v1/extra-batch-images", self.extras_batch_images_api, methods=["POST"], response_model=ExtrasBatchImagesResponse) self.app.add_api_route("/sdapi/v1/png-info", self.pnginfoapi, methods=["POST"], response_model=PNGInfoResponse) self.app.add_api_route("/sdapi/v1/progress", self.progressapi, methods=["GET"], response_model=ProgressResponse) + self.app.add_api_route("/sdapi/v1/interrupt", self.interruptapi, methods=["POST"]) def text2imgapi(self, txt2imgreq: StableDiffusionTxt2ImgProcessingAPI): sampler_index = sampler_to_index(txt2imgreq.sampler_index) @@ -176,6 +185,11 @@ class Api: return ProgressResponse(progress=progress, eta_relative=eta_relative, state=shared.state.dict(), current_image=current_image) + def interruptapi(self): + shared.state.interrupt() + + return {} + def launch(self, server_name, port): self.app.include_router(self.router) uvicorn.run(self.app, host=server_name, port=port) |