Skip to content

Commit d43d696

Browse files
iamcodingcatzedd.aifreddyaboultongradio-pr-bot
authored
feat: exception handling about file_count params of File component (#8529)
* feat: exception handling about file_count params of File component * lint * add changeset --------- Co-authored-by: zedd.ai <[email protected]> Co-authored-by: freddyaboulton <[email protected]> Co-authored-by: gradio-pr-bot <[email protected]>
1 parent 7c5fec3 commit d43d696

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

.changeset/tangy-moose-check.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"gradio": minor
3+
---
4+
5+
feat:feat: exception handling about file_count params of File component

gradio/components/file.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,14 @@ def __init__(
6969
render: If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.
7070
key: if assigned, will be used to assume identity across a re-render. Components that have the same key across a re-render will have their value preserved.
7171
"""
72+
file_count_valid_types = ["single", "multiple", "directory"]
7273
self.file_count = file_count
73-
if self.file_count in ["multiple", "directory"]:
74+
75+
if self.file_count not in file_count_valid_types:
76+
raise ValueError(
77+
f"Parameter file_count must be one of them: {file_count_valid_types}"
78+
)
79+
elif self.file_count in ["multiple", "directory"]:
7480
self.data_model = ListFiles
7581
else:
7682
self.data_model = FileData

0 commit comments

Comments
 (0)