gradio-app / gradio

Build and share delightful machine learning apps, all in Python. 🌟 Star to support our work!
http://www.gradio.app
Apache License 2.0
30.73k stars 2.29k forks source link

ImageEditor High CPU usage when idle #7586

Open NuclearGeekETH opened 4 months ago

NuclearGeekETH commented 4 months ago

Describe the bug

I am seeing high CPU usage when using ImageEditor. I noticed it a few days ago in my overall webapp here: https://github.com/NuclearGeekETH/chatGPT-web-ui. I narrowed the high CPU usage down to gr.ImageEditor and I reproduced the issue with the code below. When the tab is not active the CPU usage for Chrome drops down to 0.6% and when the tab with ImageEditor is active the CPU usage jumps up to 70+%

Have you searched existing issues? 🔎

Reproduction

import gradio as gr

def edit_image(im):
    return [im["background"].size, im["background"], im["layers"][0], im["composite"]]

with gr.Blocks() as demo:
    # Image Editor
    with gr.Tab("ImageEditor"):
        im = gr.ImageEditor(
            type="pil"
        )

        with gr.Group():
            with gr.Row():
                text_out = gr.Textbox(label="Edited Size")
            with gr.Row():
                im_out_1 = gr.Image(type="pil", label="Background")
                im_out_2 = gr.Image(type="pil", label="Layer 0")
                im_out_3 = gr.Image(type="pil", label="Composite")

        im.change(edit_image, outputs=[text_out, im_out_1, im_out_2, im_out_3], inputs=im)

demo.launch()

Screenshot

No response

Logs

No response

System Info

Gradio Environment Information:
------------------------------
Operating System: Windows
gradio version: 4.19.2
gradio_client version: 0.10.1

------------------------------------------------
gradio dependencies in your environment:

aiofiles: 23.2.1
altair: 5.2.0
fastapi: 0.110.0
ffmpy: 0.3.2
gradio-client==0.10.1 is not installed.
httpx: 0.27.0
huggingface-hub: 0.21.3
importlib-resources: 6.1.2
jinja2: 3.1.3
markupsafe: 2.1.5
matplotlib: 3.8.3
numpy: 1.26.4
orjson: 3.9.15
packaging: 23.2
pandas: 2.2.1
pillow: 10.2.0
pydantic: 2.6.3
pydub: 0.25.1
python-multipart: 0.0.9
pyyaml: 6.0.1
ruff: 0.3.0
semantic-version: 2.10.0
tomlkit==0.12.0 is not installed.
typer: 0.9.0
typing-extensions: 4.10.0
uvicorn: 0.27.1
authlib; extra == 'oauth' is not installed.
itsdangerous; extra == 'oauth' is not installed.

gradio_client dependencies in your environment:

fsspec: 2024.2.0
httpx: 0.27.0
huggingface-hub: 0.21.3
packaging: 23.2
typing-extensions: 4.10.0
websockets: 11.0.3

Severity

I can work around it

uebian commented 3 months ago

Encountering the same issue