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

ExamplePicker #7411

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

ExamplePicker #7411

wants to merge 3 commits into from

Conversation

MarcSkovMadsen
Copy link
Collaborator

@MarcSkovMadsen MarcSkovMadsen commented Oct 17, 2024

Closing #7397

Illustration

example_picker.mp4

Todo

  • move binding to Example
  • Support Buttons background thumbnails
  • Support Button icons
  • Support button_kwargs to enable styling of the buttons.
  • Support layout_type (FlexBox of Buttons or Column/ Table of Rows)
  • Make sure .value is re-triggered if an example is reselected.
  • Try many examples including Gradio examples
  • Align margin with other widgets
  • Create Interface(examples, inputs, outputs) component
  • Update ImageRecognition example
  • Update panel-mermaid editor example
  • Docstrings
  • Tests
  • Reference Guide

@@ -0,0 +1,295 @@
import os
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

  • The Gradio Examples has another api and many more (advanced) features like batch inference and example caching. Should we align closer with that api?

@@ -0,0 +1,295 @@
import os
import re
Copy link
Collaborator Author

@MarcSkovMadsen MarcSkovMadsen Oct 20, 2024

Choose a reason for hiding this comment

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

Gradio also displayes the examples in a table. I display using Panes and in a Column. Should we display using Tabulator instead. The pro of not using Tabulator is that we can display everything. The cons is that we might need to instantiate a large number of Bokeh models which is slow. And I don't know if we can make it look nice.

Gradio

image

import gradio as gr
from PIL import Image
import pandas as pd

# Example Data
image_example = Image.new('RGB', (100, 100), color = 'red')  # Red square image

examples = [
    ["Hello, World!", 42, 3.14, image_example, pd.DataFrame({"x": [1,2], "y": [1,2]})],
    ["Another text", 7, 0.001, image_example, pd.DataFrame({"x": [3,4], "y": [1,2]},)]
]

with gr.Blocks() as demo:
    gr.Examples(
        examples=examples,
        inputs=[gr.Textbox(), gr.Number(), gr.Number(), gr.Image(), gr.DataFrame()],
    )

demo.launch()

Panel

image

import gradio as gr
from PIL import Image
import pandas as pd
import panel as pn

pn.extension()

image_example = Image.new('RGB', (100, 100), color = 'red')  # Red square image

samples = [
    ["Hello, World!", 42, 3.14, image_example, pd.DataFrame({"x": [1,2], "y": [1,2]})],
    ["Another text", 7, 0.001, image_example, pd.DataFrame({"x": [3,4], "y": [1,2]},)]
]

targets = [pn.widgets.TextInput(), pn.widgets.IntInput(), pn.widgets.NumberInput(), pn.widgets.Tabulator()]

pn.widgets.Examples(*samples, layout=pn.Row, targets=targets, sizing_mode="stretch_width").servable()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in progress type: enhancement Minor feature or improvement to an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant