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
34k stars 2.58k forks source link

Parameter 'file_types' in gr.File() is unusable #9691

Closed xxxpsyduck closed 1 month ago

xxxpsyduck commented 1 month ago

Describe the bug

when specifying file_types in gr.File, the is_valid_file will be called:

https://github.com/gradio-app/gradio/blob/fd0264f3358ef848690eceacb75481212dceecf0/gradio/components/file.py#L129-L134

https://github.com/gradio-app/gradio/blob/fd0264f3358ef848690eceacb75481212dceecf0/client/python/gradio_client/utils.py#L690-L704 the call to get_mimetype() in line 691 is wrong: https://github.com/gradio-app/gradio/blob/fd0264f3358ef848690eceacb75481212dceecf0/client/python/gradio_client/utils.py#L668-L674 because it will call to mimetypes.guess_type(): image So if I have docx in the file_types:

file_type = 'docx'
mime_type_split[1] = 'vnd.openxmlformats-officedocument.wordprocessingml.document'

I believe we should change get_mimetype() to get_extenstion() instead: https://github.com/gradio-app/gradio/blob/fd0264f3358ef848690eceacb75481212dceecf0/client/python/gradio_client/utils.py#L677-L687

So everything will be correct: image

Have you searched existing issues? πŸ”Ž

Reproduction

As above

Screenshot

No response

Logs

No response

System Info

Gradio Environment Information:
------------------------------
Operating System: Linux
gradio version: 5.0.2
gradio_client version: 1.4.0

Severity

Blocking usage of gradio

xxxpsyduck commented 1 month ago

Update: already discussed at #9646 but I want to propose a different fix here