diff options
author | Billy Cao <aliencaocao@gmail.com> | 2022-11-03 05:08:26 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-03 05:08:26 +0000 |
commit | 688aa2c9c1ce6cf65c43b6113411a185e294412b (patch) | |
tree | 32514b496717c3375988e180d51daa608b045e60 /modules/api/api.py | |
parent | fb1374791bf4b4c9b49de5378f29b12fdabcac97 (diff) | |
parent | d98eacea40c7a40227f36dbea9cf92f90489310b (diff) | |
download | stable-diffusion-webui-gfx803-688aa2c9c1ce6cf65c43b6113411a185e294412b.tar.gz stable-diffusion-webui-gfx803-688aa2c9c1ce6cf65c43b6113411a185e294412b.tar.bz2 stable-diffusion-webui-gfx803-688aa2c9c1ce6cf65c43b6113411a185e294412b.zip |
Merge branch 'AUTOMATIC1111:master' into fix_nowebui_arg
Diffstat (limited to 'modules/api/api.py')
-rw-r--r-- | modules/api/api.py | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/modules/api/api.py b/modules/api/api.py index 97497f3f..71c9c160 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.api.models import * @@ -28,6 +30,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() @@ -39,6 +47,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) @@ -169,15 +178,7 @@ class Api: progress = min(progress, 1) - # copy from check_progress_call of ui.py - - if shared.parallel_processing_allowed: - if shared.state.sampling_step - shared.state.current_image_sampling_step >= shared.opts.show_progress_every_n_steps and shared.state.current_latent is not None: - if shared.opts.show_progress_grid: - shared.state.current_image = samples_to_image_grid(shared.state.current_latent) - else: - shared.state.current_image = sample_to_image(shared.state.current_latent) - shared.state.current_image_sampling_step = shared.state.sampling_step + shared.state.set_current_image() current_image = None if shared.state.current_image and not req.skip_current_image: @@ -185,6 +186,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) |