Skip to content

Raise warning when trying to cache examples but not all inputs have examples#2279

Merged
freddyaboulton merged 6 commits into
mainfrom
2239-helpful-error-message-partial-examples
Sep 20, 2022
Merged

Raise warning when trying to cache examples but not all inputs have examples#2279
freddyaboulton merged 6 commits into
mainfrom
2239-helpful-error-message-partial-examples

Conversation

@freddyaboulton
Copy link
Copy Markdown
Collaborator

@freddyaboulton freddyaboulton commented Sep 15, 2022

Description

Fixes #2239

I originally intended to raise an exception if the length of input_with_examples did not match the length of the non_none_examples but 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:

  • I have performed a self-review of my own code
  • My code follows the style guidelines of this project
  • I have commented my code in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

@github-actions
Copy link
Copy Markdown
Contributor

All the demos for this PR have been deployed at https://huggingface.co/spaces/gradio-pr-deploys/pr-2279-all-demos

@freddyaboulton freddyaboulton force-pushed the 2239-helpful-error-message-partial-examples branch from 3667380 to 277e26b Compare September 15, 2022 21:20
@freddyaboulton freddyaboulton changed the title Raise error message when trying to cache partial examples Raise warning when trying to cache examples but not all inputs have examples Sep 16, 2022
@freddyaboulton freddyaboulton force-pushed the 2239-helpful-error-message-partial-examples branch from cc1fffa to 17fbf76 Compare September 16, 2022 18:25
@freddyaboulton freddyaboulton marked this pull request as ready for review September 16, 2022 18:29
Comment thread gradio/examples.py Outdated
"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."
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Will probably need to be re-formatted.

Comment thread gradio/examples.py Outdated
example_id: The id of the example to process (zero-indexed).
"""
processed_input = self.processed_examples[example_id]
self.inputs_with_examples
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Extraneous?

@abidlabs
Copy link
Copy Markdown
Member

abidlabs commented Sep 16, 2022

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

Comment thread test/test_examples.py Outdated
)

def many_missing(a, b, c):
a * b
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

very nit

Suggested change
a * b
return a * b

@freddyaboulton freddyaboulton force-pushed the 2239-helpful-error-message-partial-examples branch from 487e0f7 to f9d2818 Compare September 20, 2022 14:43
@freddyaboulton freddyaboulton merged commit b8fc551 into main Sep 20, 2022
@freddyaboulton freddyaboulton deleted the 2239-helpful-error-message-partial-examples branch September 20, 2022 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Interfaces which provide partial examples will crash on Spaces

2 participants