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
33.41k stars 2.53k forks source link

Clear button puts slider at zero while it should always have a default value #6720

Closed RRighart closed 10 months ago

RRighart commented 10 months ago

Describe the bug

My App intends to load images and run object detection. This all works. But when I am hitting the clear button underneath the image that is displayed, it not only removes the image (which is desired), but it also sets the default value of the slider at 0. This slider regulates the confidence value of the object detection and I’d prefer to always let it have a value of 0.20, sothat the display gets not filled with bounding boxes. This was actually working before with a previous version of Gradio (gradio==3.17.0) but now it keeps on setting it at zero (gradio==4.8.0). How could one set and leave the slider at the default value of 0.20 independent of pushing the clear button? Thank you very much in advance for your help!

Have you searched existing issues? 🔎

Reproduction

inputs = [
    gr.Image(type="filepath", label="Input"),
    gr.Slider(minimum=0.0, maximum=1.0, value=0.2, step=0.05, label="Confidence Threshold", interactive=True),
]

outputs = [
    gr.Image(type="filepath"),
]

css = ".output_image {height: 40rem !important; width: 100% !important;}"

demo_app = gr.Interface(
    fn=yolov7_inference,
    inputs=inputs,
    outputs=outputs,
    title="My App",
    examples = [['example1.JPG'], ['example2.JPG'], ['example3.JPG']],
    css=css,
    cache_examples=False,
)

Screenshot

No response

Logs

No response

System Info

gradio==4.8.0

Severity

I can work around it

abidlabs commented 10 months ago

Hi @RRighart this is actually the intended behavior of the Clear button. The Clear button sets inputs components to have a null-ish value, it does not reset it. For example, for a gr.Textbox(), it would set the value to be "", not the original default value.

In your case, I see a couple of options:

RRighart commented 10 months ago

Thank you for your reply, I will indeed use gr.Blocks().