Raise warning when trying to cache examples but not all inputs have examples#2279
Merged
freddyaboulton merged 6 commits intoSep 20, 2022
Merged
Conversation
Contributor
|
All the demos for this PR have been deployed at https://huggingface.co/spaces/gradio-pr-deploys/pr-2279-all-demos |
3667380 to
277e26b
Compare
cc1fffa to
17fbf76
Compare
abidlabs
reviewed
Sep 16, 2022
| "Examples are being cached but not all input components have " | ||
| "example values. This may result in an exception being thrown by " | ||
| "your function. If you do get an error while caching examples, make " | ||
| "sure all of your inputs have example values for all of your examples." |
Member
There was a problem hiding this comment.
Suggested change
| "sure all of your inputs have example values for all of your examples." | |
| "sure all of your inputs have example values for all of your examples or you provide default values for those particular parameters in your function." |
Member
There was a problem hiding this comment.
Will probably need to be re-formatted.
abidlabs
reviewed
Sep 16, 2022
| example_id: The id of the example to process (zero-indexed). | ||
| """ | ||
| processed_input = self.processed_examples[example_id] | ||
| self.inputs_with_examples |
Member
|
What about an example like this: def many_missing(a, b, c):
return a * b
gr.Interface(
many_missing,
inputs=["text", "number", "number"],
outputs=["text"],
examples=[["foo", None, None], ["bar", None, None]],
cache_examples=True,
)`Because the 2nd and 3rd parameters are missing from all examples, it won't raise the warning. But I believe it should right? Otherwise, LGTM |
abidlabs
approved these changes
Sep 16, 2022
abidlabs
reviewed
Sep 16, 2022
| ) | ||
|
|
||
| def many_missing(a, b, c): | ||
| a * b |
Member
There was a problem hiding this comment.
very nit
Suggested change
| a * b | |
| return a * b |
487e0f7 to
f9d2818
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #2239
I originally intended to raise an exception if the length of
input_with_examplesdid not match the length of thenon_none_examplesbut that would prevent a user from deliberately providing partial examples and then just adding defaults to their prediction function.I'm raising a warning instead. It's not a change in behavior so it's low risk of breaking someone's current workflow. If users get an exception when they try to cache an incomplete example, the warning message will hopefully point them in the right direction.
Checklist: