Skip to content

Commit 88f46a5

Browse files
committed
update progress response model
1 parent e9c6c2a commit 88f46a5

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

modules/api/api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def __init__(self, app, queue_lock):
6161
self.app.add_api_route("/sdapi/v1/extra-single-image", self.extras_single_image_api, methods=["POST"], response_model=ExtrasSingleImageResponse)
6262
self.app.add_api_route("/sdapi/v1/extra-batch-images", self.extras_batch_images_api, methods=["POST"], response_model=ExtrasBatchImagesResponse)
6363
self.app.add_api_route("/sdapi/v1/png-info", self.pnginfoapi, methods=["POST"], response_model=PNGInfoResponse)
64-
self.app.add_api_route("/sdapi/v1/progress", self.progressapi, methods=["GET"])
64+
self.app.add_api_route("/sdapi/v1/progress", self.progressapi, methods=["GET"], response_model=ProgressResponse)
6565

6666
def text2imgapi(self, txt2imgreq: StableDiffusionTxt2ImgProcessingAPI):
6767
sampler_index = sampler_to_index(txt2imgreq.sampler_index)
@@ -171,7 +171,7 @@ def progressapi(self):
171171
# copy from check_progress_call of ui.py
172172

173173
if shared.state.job_count == 0:
174-
return ProgressResponse(progress=0, eta_relative=0, state=shared.state.js())
174+
return ProgressResponse(progress=0, eta_relative=0, state=shared.state.dict())
175175

176176
# avoid dividing zero
177177
progress = 0.01
@@ -187,7 +187,7 @@ def progressapi(self):
187187

188188
progress = min(progress, 1)
189189

190-
return ProgressResponse(progress=progress, eta_relative=eta_relative, state=shared.state.js())
190+
return ProgressResponse(progress=progress, eta_relative=eta_relative, state=shared.state.dict())
191191

192192
def launch(self, server_name, port):
193193
self.app.include_router(self.router)

modules/api/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import inspect
22
from click import prompt
3-
from pydantic import BaseModel, Field, Json, create_model
3+
from pydantic import BaseModel, Field, create_model
44
from typing import Any, Optional
55
from typing_extensions import Literal
66
from inflection import underscore
@@ -160,4 +160,4 @@ class PNGInfoResponse(BaseModel):
160160
class ProgressResponse(BaseModel):
161161
progress: float = Field(title="Progress", description="The progress with a range of 0 to 1")
162162
eta_relative: float = Field(title="ETA in secs")
163-
state: Json = Field(title="State", description="The current state snapshot")
163+
state: dict = Field(title="State", description="The current state snapshot")

modules/shared.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ def nextjob(self):
147147
def get_job_timestamp(self):
148148
return datetime.datetime.now().strftime("%Y%m%d%H%M%S") # shouldn't this return job_timestamp?
149149

150-
def js(self):
150+
def dict(self):
151151
obj = {
152152
"skipped": self.skipped,
153153
"interrupted": self.skipped,
@@ -158,7 +158,7 @@ def js(self):
158158
"sampling_steps": self.sampling_steps,
159159
}
160160

161-
return json.dumps(obj)
161+
return obj
162162

163163

164164
state = State()

0 commit comments

Comments
 (0)