Skip to content

Some enhancements to gr.Examples#2131

Merged
abidlabs merged 3 commits into
mainfrom
exs
Aug 31, 2022
Merged

Some enhancements to gr.Examples#2131
abidlabs merged 3 commits into
mainfrom
exs

Conversation

@abidlabs
Copy link
Copy Markdown
Member

@abidlabs abidlabs commented Aug 30, 2022

Test by running:

with gr.Blocks(css="#ex{background-color: red}") as demo:
    t = gr.Textbox()
    gr.Examples(["hi", "hello"], t, elem_id="ex")
    
demo.launch()

Test by running:

def test(x):
    time.sleep(2)
    return "xx"

with gr.Blocks() as demo:
    t = gr.Textbox()
    o = gr.Textbox()
    ex = gr.Examples(["hi", "hello"], t, o, test, run_on_click=True)
    
demo.launch()
  • Also adds documentation around rendering gr.Examples() using components that are placed later in the UI as we tend to get questions around this frequently (e.g. #2042)

@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-2131-all-demos

Copy link
Copy Markdown
Contributor

@aliabid94 aliabid94 left a comment

Choose a reason for hiding this comment

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

LGTM

Comment thread gradio/examples.py Outdated
_postprocess=False,
queue=False,
)
if self.run_on_click and not (self.cache_examples):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

remove parentheses around (self.cache_examples)

Here's a full code example:

```python

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

remove blank line at start

@abidlabs
Copy link
Copy Markdown
Member Author

Thanks for the review @aliabid94!

@abidlabs
Copy link
Copy Markdown
Member Author

I'm going to merge this in because the flaky tests don't seem to have anything to do with Gradio, and I'm corresponding with the Spaces team to figure out what the underlying reason is

@abidlabs abidlabs merged commit df25d63 into main Aug 31, 2022
@abidlabs abidlabs deleted the exs branch August 31, 2022 01:06
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.

Ability to pass elem_id to Examples In Examples Component, if fn is provided and cache_examples=False, fn is never run

2 participants