Fix: file_types checking bug (#9678)

* Fix: file_types check

* add changeset

---------

Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
This commit is contained in:
Zhiyang Guo 2024-10-15 07:45:58 +08:00 committed by GitHub
parent 35bebf38eb
commit a25a26e208
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 5 deletions

View File

@ -0,0 +1,6 @@
---
"gradio": patch
"gradio_client": patch
---
fix:Fix: `file_types` checking bug

View File

@ -689,17 +689,15 @@ def get_extension(encoding: str) -> str | None:
def is_valid_file(file_path: str, file_types: list[str]) -> bool: def is_valid_file(file_path: str, file_types: list[str]) -> bool:
mime_type = get_mimetype(file_path) mime_type = get_mimetype(file_path)
if mime_type is None:
return False
for file_type in file_types: for file_type in file_types:
if file_type == "file": if file_type == "file":
return True return True
if file_type.startswith("."): if file_type.startswith("."):
file_type = file_type.lstrip(".").lower() file_type = file_type.lstrip(".").lower()
mime_type_split = mime_type.lower().split("/") file_ext = Path(file_path).suffix.lstrip(".").lower()
if file_type == mime_type_split[1]: if file_type == file_ext:
return True return True
elif mime_type.startswith(f"{file_type}/"): elif mime_type is not None and mime_type.startswith(f"{file_type}/"):
return True return True
return False return False