-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Improvements to gr.Examples
: adds events as attributes and documents, them, adds sample_labels
, and visible
properties
#8733
Conversation
🪼 branch checks and previews
Install Gradio from this PR pip install https://gradio-builds.s3.amazonaws.com/f9d31cd15c783f747253934990591a1d9a04212a/gradio-4.37.2-py3-none-any.whl Install Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@f9d31cd15c783f747253934990591a1d9a04212a#subdirectory=client/python" Install Gradio JS Client from this PR npm install https://gradio-builds.s3.amazonaws.com/f9d31cd15c783f747253934990591a1d9a04212a/gradio-client-1.2.1.tgz |
🦄 change detectedThis Pull Request includes changes to the following packages.
With the following changelog entry.
Maintainers or the PR author can modify the PR title to modify this entry.
|
gr.Examples
: adds events as attributes and documents, them, adds sample_labels
, and visible
properties
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm having issues using the example_labels
prop. I get the ValueError even when my example_labels list is the same length as the examples.
ValueError: The length of `example_labels` should be the same as the number of examples
Tried with this demo:
import gradio as gr
def calculator(num1, operation, num2):
if operation == "add":
return num1 + num2
elif operation == "subtract":
return num1 - num2
elif operation == "multiply":
return num1 * num2
elif operation == "divide":
return num1 / num2
def calculator2(num1, operation, num2):
if operation == "add":
return num1 + num2
elif operation == "subtract":
return num1 - num2
elif operation == "multiply":
return num1 * num2 * num1
elif operation == "divide":
return num1 / num2
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
num_1 = gr.Number(value=4)
operation = gr.Radio(["add", "subtract", "multiply", "divide"])
num_2 = gr.Number(value=0)
submit_btn = gr.Button(value="Calculate")
with gr.Column():
result = gr.Number()
submit_btn.click(
calculator, inputs=[num_1, operation, num_2], outputs=[result], api_name=False
)
examples = gr.Examples(
examples=[
[5, "add", 3],
[4, "divide", 2],
[-4, "multiply", 2.5],
[0, "subtract", 1.2],
],
inputs=[num_1, operation, num_2],
example_labels=["add", "divide", "multiply", "subtract"],
)
if __name__ == "__main__":
demo.launch()
Am I missing something?
Co-authored-by: Ali Abdalla <ali.si3luwa@gmail.com>
Co-authored-by: Ali Abdalla <ali.si3luwa@gmail.com>
Thanks @aliabd, let me take a look |
Should be fixed now if you can take another look @aliabd! |
Co-authored-by: Ali Abdalla <ali.si3luwa@gmail.com>
I'm not sure what I'm looking at here, aren't the labels supposed to show up in the UI? Screen.Recording.2024-07-10.at.10.18.29.AM.mov |
what?? coulda sworn this was working. you don't need to advertise my bugs in HD video 😆 |
anyways I can repro, will fix in a bit |
Thanks @aliabd. Turns out that my original approach was broken and I had gotten lucky with my test case. Should be fixed now. Here are a couple of test cases: (your original example) import gradio as gr
def calculator(num1, operation, num2):
if operation == "add":
return num1 + num2
elif operation == "subtract":
return num1 - num2
elif operation == "multiply":
return num1 * num2
elif operation == "divide":
return num1 / num2
def calculator2(num1, operation, num2):
if operation == "add":
return num1 + num2
elif operation == "subtract":
return num1 - num2
elif operation == "multiply":
return num1 * num2 * num1
elif operation == "divide":
return num1 / num2
with gr.Blocks() as demo:
with gr.Row():
with gr.Column():
num_1 = gr.Number(value=4)
operation = gr.Radio(["add", "subtract", "multiply", "divide"])
num_2 = gr.Number(value=0)
submit_btn = gr.Button(value="Calculate")
with gr.Column():
result = gr.Number()
submit_btn.click(
calculator, inputs=[num_1, operation, num_2], outputs=[result], api_name=False
)
examples = gr.Examples(
examples=[
[5, "add", 3],
[4, "divide", 2],
[-4, "multiply", 2.5],
[0, "subtract", 1.2],
],
inputs=[num_1, operation, num_2],
example_labels=["add", "divide", "multiply", "subtract"],
)
if __name__ == "__main__":
demo.launch() and import gradio as gr
with gr.Blocks() as demo:
t=gr.Textbox()
i=gr.Image()
gr.Examples(examples=[["cheetah", "https://github.com/raw/gradio-app/gradio/main/test/test_files/bus.png"], ["cat", "https://github.com/raw/gradio-app/gradio/main/test/test_files/bus.png"]], inputs=[t, i],
example_labels=["big cat", "small cat"])
demo.launch() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Everything works great! 🎉 Thanks @abidlabs!
Thanks for testing @aliabd! |
Makes several enhancements to
gr.Examples
:load_input_event
andcache_event
as public attributes and documents them (closes: Add.then
togr.Examples
#8710)visible
prop (closes: Supportvisible
option ingr.Examples
#6390)example_labels
prop (closes: gr.Examples Enable for each example to have a label and a value #4268)