Skip to content

armgit / rembg

Public Imported from GitHub
0

Rembg is a tool to remove images background

Fix model not being kept in memory between Gradio requests (#816)

Daniel Gatis226680db6220
diff --git a/rembg/commands/s_command.py b/rembg/commands/s_command.py
index 5cf5be6..3e49fe9 100644
--- a/rembg/commands/s_command.py
+++ b/rembg/commands/s_command.py
@@ -279,7 +279,12 @@ def s_command(port: int, host: str, log_level: str, threads: int) -> None:
if cmd_args:
kwargs.update(json.loads(cmd_args))
- kwargs["session"] = new_session(model, **kwargs)
+
+ session = sessions.get(model)
+ if session is None:
+ session = new_session(model, **kwargs)
+ sessions[model] = session
+ kwargs["session"] = session
with open(input_path, "rb") as i:
with open(output_path, "wb") as o: