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.69k stars 2.28k forks source link

Image component preprocessing problem #8412

Closed 2265865006 closed 2 weeks ago

2265865006 commented 1 month ago

Describe the bug

I have some doubts about the current Image component, I may be too entangled in the details. When I upload an image on the web page, if my suffix is jpg and Gradio receives an image with the suffix jpeg, and the md5 of the two is different, I guess some pre-processing may be done on the image. But I think the Image component should not make additional changes to the uploaded content, and the Image component should only focus on displaying or passing the content. Is there any additional consideration? I now use gr. File as a substitute

Have you searched existing issues? 🔎

Reproduction

import gradio as gr

def img_test(img):
    print(img)

with gr.Blocks() as demo:
    image_debug = gr.Image(visible=True,height=500,width="auto",interactive=False,label="output",format="png",type="filepath")

    btn= gr.Button(value="process")

    btn.click(fn=img_test,inputs=[image_debug],api_name="process")

if __name__ == '__main__':
    demo.title = "Demo"
    demo.queue(api_open=True).launch(share=False,server_port=7860)

Screenshot

No response

Logs

No response

System Info

gradio                  4.31.4
gradio_client           0.16.4

Severity

Blocking usage of gradio

pngwn commented 3 weeks ago

The image does do some processing because we need to get the image into a format that the user can do something with (turn it into a np array, PIL image, or file path with a corresponding file). We need to do this because we don't know if a user wants the image exactly as it is or wants to process it in some way.

What is the actual bug here?

2265865006 commented 3 weeks ago

@pngwn From my current requirements for using the gr.Image component, when I want the corresponding file path, I want to get the image path without any processing, which may be helpful for alignment with the results of other programs. But now I have an alternative plan, so I do not have a strong demand for the solution of this problem, just to discuss the possible unreasonable.

pngwn commented 3 weeks ago

You can set preprocess false on the image to disable any processing and you will get a dictionary including the file path to the original image.

2265865006 commented 2 weeks ago

@pngwn Thank you. This will help me