From b1eec6907a71cd0f289fb322860806966dff528f Mon Sep 17 00:00:00 2001 From: Sean Sube Date: Wed, 1 Feb 2023 22:31:01 -0600 Subject: [PATCH] fix(api): write border and upscale to params file --- api/onnx_web/output.py | 17 ++++++++++------- api/onnx_web/params.py | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/api/onnx_web/output.py b/api/onnx_web/output.py index 312ee9dc..dae2f856 100644 --- a/api/onnx_web/output.py +++ b/api/onnx_web/output.py @@ -21,22 +21,25 @@ def json_params( upscale: Optional[UpscaleParams] = None, border: Optional[Border] = None, ) -> Any: + json = { + 'output': output, + 'params': params.tojson(), + } + if upscale is not None and border is not None: size = upscale.resize(size.add_border(border)) if upscale is not None: + json['upscale'] = upscale.tojson() size = upscale.resize(size) if border is not None: + json['border'] = border.tojson() size = size.add_border(border) - return { - 'border': border.tojson(), - 'output': output, - 'params': params.tojson(), - 'size': size.tojson(), - 'upscale': upscale.tojson(), - } + json['size'] = size + + return def save_image(ctx: ServerContext, output: str, image: Image.Image) -> str: diff --git a/api/onnx_web/params.py b/api/onnx_web/params.py index 03856afb..a087de42 100644 --- a/api/onnx_web/params.py +++ b/api/onnx_web/params.py @@ -28,6 +28,14 @@ class Border: def __str__(self) -> str: return '%s %s %s %s' % (self.left, self.top, self.right, self.bottom) + def tojson(self): + return { + 'left': self.left, + 'right': self.right, + 'top': self.top, + 'bottom': self.bottom, + } + @classmethod def even(cls, all: int): return Border(all, all, all, all) @@ -149,3 +157,11 @@ class UpscaleParams(): def resize(self, size: Size) -> Size: return Size(size.width * self.outscale, size.height * self.outscale) + + def tojson(self): + return { + 'model': self.upscale_model, + 'scale': self.scale, + 'outscale': self.outscale, + # TODO: add more + }