Closed xxxpsyduck closed 1 month ago
when specifying file_types in gr.File, the is_valid_file will be called:
file_types
is_valid_file
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(): So if I have docx in the file_types:
get_mimetype()
mimetypes.guess_type()
docx
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
get_extenstion()
So everything will be correct:
As above
No response
Gradio Environment Information: ------------------------------ Operating System: Linux gradio version: 5.0.2 gradio_client version: 1.4.0
Blocking usage of gradio
Update: already discussed at #9646 but I want to propose a different fix here
Describe the bug
when specifying
file_types
in gr.File, theis_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 tomimetypes.guess_type()
: So if I havedocx
in thefile_types
:I believe we should change
get_mimetype()
toget_extenstion()
instead: https://github.com/gradio-app/gradio/blob/fd0264f3358ef848690eceacb75481212dceecf0/client/python/gradio_client/utils.py#L677-L687So everything will be correct:
Have you searched existing issues? π
Reproduction
As above
Screenshot
No response
Logs
No response
System Info
Severity
Blocking usage of gradio