Skip to content

Commit 02ca21f

Browse files
committed
Add --no-ui flag to server command to reduce idle CPU usage (#824)
Gradio's internal queue and polling mechanism runs continuously even when the server is idle, causing constant ~7% CPU usage. The new --no-ui flag skips mounting the Gradio interface and runs the FastAPI app directly, bringing idle CPU back to near 0%.
1 parent 5e10e9b commit 02ca21f

2 files changed

Lines changed: 21 additions & 5 deletions

File tree

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,12 @@ rembg s --host 0.0.0.0 --port 7000 --log_level info
184184

185185
For complete API documentation, visit: `http://localhost:7000/api`
186186

187+
**Disable the Gradio UI (reduces idle CPU usage):**
188+
189+
```shell
190+
rembg s --no-ui
191+
```
192+
187193
**Remove background from an image URL:**
188194

189195
```shell

rembg/commands/s_command.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,14 @@
5555
show_default=True,
5656
help="number of worker threads",
5757
)
58-
def s_command(port: int, host: str, log_level: str, threads: int) -> None:
58+
@click.option(
59+
"--no-ui",
60+
is_flag=True,
61+
default=False,
62+
show_default=True,
63+
help="disable the Gradio UI (reduces idle CPU usage)",
64+
)
65+
def s_command(port: int, host: str, log_level: str, threads: int, no_ui: bool) -> None:
5966
"""
6067
Command-line interface for running the FastAPI web server.
6168
@@ -323,8 +330,11 @@ def inference(input_path, model, *args):
323330
print(
324331
f"To access the API documentation, go to http://{'localhost' if host == '0.0.0.0' else host}:{port}/api"
325332
)
326-
print(
327-
f"To access the UI, go to http://{'localhost' if host == '0.0.0.0' else host}:{port}"
328-
)
333+
if not no_ui:
334+
print(
335+
f"To access the UI, go to http://{'localhost' if host == '0.0.0.0' else host}:{port}"
336+
)
329337

330-
uvicorn.run(gr_app(app), host=host, port=port, log_level=log_level)
338+
uvicorn.run(
339+
app if no_ui else gr_app(app), host=host, port=port, log_level=log_level
340+
)

0 commit comments

Comments
 (0)