Rembg is a tool to remove images background
Avoid redundant session creation in HTTP server
dmitry-kotorov71ac419dc08b
diff --git a/rembg/commands/s_command.py b/rembg/commands/s_command.pyindex 1f70cb7..eca5046 100644--- a/rembg/commands/s_command.py+++ b/rembg/commands/s_command.py@@ -197,12 +197,15 @@ def s_command(port: int, host: str, log_level: str, threads: int) -> None:except Exception:pass+ session = sessions.get(commons.model)+ if session is None:+ session = new_session(commons.model, **kwargs)+ sessions[commons.model] = session+return Response(remove(content,- session=sessions.setdefault(- commons.model, new_session(commons.model, **kwargs)- ),+ session=session,alpha_matting=commons.a,alpha_matting_foreground_threshold=commons.af,alpha_matting_background_threshold=commons.ab,