Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Dropdown Example component and example processing logic #6075

Merged
merged 3 commits into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions gradio/components/dropdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,9 @@ def postprocess(self, y):
return y

def as_example(self, input_data):
if self.multiselect:
return [
next((c[0] for c in self.choices if c[1] == data), None)
for data in input_data
]
return next((c[0] for c in self.choices if c[1] == input_data), None)
18 changes: 8 additions & 10 deletions gradio/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,14 @@ def create(self) -> None:

async def load_example(example_id):
processed_example = self.non_none_processed_examples[example_id]
examples = utils.resolve_singleton(processed_example)

return (
update(value=examples, **self.dataset.component_props[0])
if not isinstance(examples, list)
else [
update(value=ex, **self.dataset.component_props[i])
for i, ex in enumerate(examples)
]
)
if len(self.inputs_with_examples) == 1:
return update(
value=processed_example[0], **self.dataset.component_props[0]
)
return [
update(value=processed_example[i], **self.dataset.component_props[i])
for i in range(len(self.inputs_with_examples))
Copy link
Member Author

@abidlabs abidlabs Oct 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be self.inputs_with_examples here not examples

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah cool. I have to admit all of this code confused me a great deal. I still don't know what all of the references to different examples/ inputs are.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the code for examples is messy, will clean up at some point. Your PR using gr.update is nice though, captures an edge case we didn’t think about originally!

]

if Context.root_block:
self.load_input_event = self.dataset.click(
Expand Down