Skip to content

Commit

Permalink
sonar lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Feb 20, 2023
1 parent c5eae68 commit 40e396a
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions api/onnx_web/chain/upscale_resrgan.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def load_resrgan(
return cache_pipe

if not path.isfile(model_path):
raise Exception("Real ESRGAN model not found at %s" % model_path)
raise FileNotFoundError("Real ESRGAN model not found at %s" % model_path)

if params.format == "onnx":
# use ONNX acceleration, if available
Expand Down Expand Up @@ -66,7 +66,7 @@ def load_resrgan(
scale=params.scale,
)
else:
raise Exception("unknown platform %s" % params.format)
raise ValueError("unknown platform %s" % params.format)

dni_weight = None
if params.upscale_model == TAG_X4_V3 and params.denoise != 1:
Expand Down
2 changes: 1 addition & 1 deletion api/onnx_web/chain/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def process_tile_spiral(
**kwargs,
) -> Image.Image:
if scale != 1:
raise Exception("unsupported scale")
raise ValueError("unsupported scale")

width, height = source.size
image = Image.new("RGB", (width * scale, height * scale))
Expand Down
6 changes: 3 additions & 3 deletions api/onnx_web/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def mask_filter_gaussian_multiply(
"""
noise = mask_filter_none(mask, dims, origin)

for i in range(rounds):
for _i in range(rounds):
blur = noise.filter(ImageFilter.GaussianBlur(5))
noise = ImageChops.multiply(noise, blur)

Expand All @@ -45,7 +45,7 @@ def mask_filter_gaussian_screen(
"""
noise = mask_filter_none(mask, dims, origin)

for i in range(rounds):
for _i in range(rounds):
blur = noise.filter(ImageFilter.GaussianBlur(5))
noise = ImageChops.screen(noise, blur)

Expand Down Expand Up @@ -88,7 +88,7 @@ def noise_source_gaussian(
noise = noise_source_uniform(source, dims, origin)
noise.paste(source, origin)

for i in range(rounds):
for _i in range(rounds):
noise = noise.filter(ImageFilter.GaussianBlur(5))

return noise
Expand Down
4 changes: 2 additions & 2 deletions api/onnx_web/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,8 +803,8 @@ def ready():
done, progress = executor.done(output_file)

if done is None:
file = base_join(context.output_path, output_file)
if path.exists(file):
output = base_join(context.output_path, output_file)
if path.exists(output):
return ready_reply(True)

return ready_reply(done, progress=progress)
Expand Down
4 changes: 2 additions & 2 deletions api/onnx_web/server/device_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_device(self) -> DeviceParams:
with self.device_index.get_lock():
device_index = self.device_index.value
if device_index < 0:
raise Exception("job has not been assigned to a device")
raise ValueError("job has not been assigned to a device")
else:
device = self.devices[device_index]
logger.debug("job %s assigned to device %s", self.key, device)
Expand All @@ -57,7 +57,7 @@ def get_progress_callback(self) -> ProgressCallback:
def on_progress(step: int, timestep: int, latents: Any):
on_progress.step = step
if self.is_cancelled():
raise Exception("job has been cancelled")
raise RuntimeError("job has been cancelled")
else:
logger.debug("setting progress for job %s to %s", self.key, step)
self.set_progress(step)
Expand Down
4 changes: 2 additions & 2 deletions api/onnx_web/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_not_empty(args: Any, key: str, default: Any) -> Any:
return val


def get_size(val: Union[int, str, None]) -> SizeChart:
def get_size(val: Union[int, str, None]) -> Union[int, SizeChart]:
if val is None:
return SizeChart.auto

Expand All @@ -79,7 +79,7 @@ def get_size(val: Union[int, str, None]) -> SizeChart:

return int(val)

raise Exception("invalid size")
raise ValueError("invalid size")


def run_gc(devices: List[DeviceParams] = None):
Expand Down
10 changes: 5 additions & 5 deletions api/scripts/test-memory-leak.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ test_images=0
while true;
do
curl "http://${test_host}:5000/api/txt2img?"\
'cfg=16.00&steps=35&scheduler=deis-multi&seed=-1&'\
'prompt=an+astronaut+eating+a+hamburger&negativePrompt=&'\
'model=stable-diffusion-v1-5&platform=any&'\
'upscaling=upscaling-real-esrgan-x2-plus&correction=correction-codeformer&'\
'lpw=false&width=512&height=512&upscaleOrder=correction-both' \
'cfg=16.00&steps=35&scheduler=deis-multi&seed=-1&'\
'prompt=an+astronaut+eating+a+hamburger&negativePrompt=&'\
'model=stable-diffusion-onnx-v1-5&platform=any&'\
'upscaling=upscaling-real-esrgan-x2-plus&correction=correction-codeformer&'\
'lpw=false&width=512&height=512&upscaleOrder=correction-both' \
-X 'POST' \
--compressed \
--insecure || break;
Expand Down

0 comments on commit 40e396a

Please sign in to comment.