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

adds a run_examples_on_click parameter to gr.ChatInterface mirroring the the run_on_click parameter in gr.Examples #10109

Merged
merged 36 commits into from
Dec 7, 2024

Conversation

abidlabs
Copy link
Member

@abidlabs abidlabs commented Dec 3, 2024

Small PR that adds a run_examples_on_click parameter on to gr.ChatInterface, closes: #10103

Two examples to test with:

import gradio as gr

def echo(message, history):
    return message["text"]

demo = gr.ChatInterface(
    fn=echo,
    type="messages",
    examples=[{"text": "abc"}, {"text": "hello", "files": ["files/avatar.png"]}, {"text": "hola", "files": ["files/cantina.wav"]}],
    title="Echo Bot",
    multimodal=True,
    run_examples_on_click=False,
)
demo.launch()
import random
import gradio as gr

def random_response(message, history):
    return random.choice(["Yes", "No"])

demo = gr.ChatInterface(random_response, type="messages", autofocus=False, run_examples_on_click=False, examples=["Hello", "Hi", "How are you?", "I am fine", "Thank you"])

if __name__ == "__main__":
    demo.launch()

Also fixes: #10105

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Dec 3, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-pypi-previews.s3.amazonaws.com/43acdc2c90952f63fb8f7ccc6122a1615def004a/gradio-5.8.0-py3-none-any.whl

Install Gradio Python Client from this PR

pip install "gradio-client @ git+https://github.com/gradio-app/gradio@43acdc2c90952f63fb8f7ccc6122a1615def004a#subdirectory=client/python"

Install Gradio JS Client from this PR

npm install https://gradio-npm-previews.s3.amazonaws.com/43acdc2c90952f63fb8f7ccc6122a1615def004a/gradio-client-1.8.0.tgz

Use Lite from this PR

<script type="module" src="https://gradio-lite-previews.s3.amazonaws.com/43acdc2c90952f63fb8f7ccc6122a1615def004a/dist/lite.js""></script>

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Dec 3, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

Package Version
gradio minor
website minor
  • Maintainers can select this checkbox to manually select packages to update.

With the following changelog entry.

adds a run_examples_on_click parameter to gr.ChatInterface mirroring the the run_on_click parameter in gr.Examples

Maintainers or the PR author can modify the PR title to modify this entry.

Something isn't right?

  • Maintainers can change the version label to modify the version bump.
  • If the bot has failed to detect any changes, or if this pull request needs to update multiple packages to different versions or requires a more comprehensive changelog entry, maintainers can update the changelog file directly.

@abidlabs abidlabs changed the title add param adds a run_examples_on_click parameter to gr.ChatInterface mirroring the the run_on_click parameter in gr.Examples Dec 3, 2024
@abidlabs abidlabs added the v: minor A change that requires a minor release label Dec 3, 2024
@abidlabs abidlabs marked this pull request as ready for review December 3, 2024 15:42
@freddyaboulton
Copy link
Collaborator

freddyaboulton commented Dec 4, 2024

If run_on_click=True, then images in the multimodal textbox are not displayed as images in the chatbot:

run_on_click_true_multimodal

This is not the case when run_on_click=False

run_on_click_false_multimodal

other than that LGTM!

@abidlabs
Copy link
Member Author

abidlabs commented Dec 4, 2024

Thanks yet again @freddyaboulton! Will take a look at that issue

@abidlabs
Copy link
Member Author

abidlabs commented Dec 4, 2024

Oh so the issue is actually with the default behavior hmm

@abidlabs
Copy link
Member Author

abidlabs commented Dec 4, 2024

Noticed another issue, which is that when cache_examples=True, any cached files appear on the wrong side of the chatbot:

image
import gradio as gr

def echo(message, history):
    return message["text"]

demo = gr.ChatInterface(
    fn=echo,
    type="messages",
    examples=[{"text": "hello", "files":["files/avatar.png"]}, {"text": "hola"}, {"text": "merhaba"}],
    cache_examples=True,
    title="Echo Bot",
    multimodal=True,
)
demo.launch()

@abidlabs abidlabs marked this pull request as draft December 5, 2024 03:33
@hysts
Copy link
Collaborator

hysts commented Dec 6, 2024

Thanks! Basically LGTM, but I noticed that the undo button is not working correctly for multimodal examples run_examples_on_click=True. Looks like it was broken from the beginning.

out.mp4

@abidlabs
Copy link
Member Author

abidlabs commented Dec 6, 2024

Dang okay thanks for flagging @hysts!

Copy link
Collaborator

@hysts hysts left a comment

Choose a reason for hiding this comment

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

As the undo issue is not introduced in this PR, I guess it can be fixed in another PR. So I'll approve this PR for now.

@abidlabs
Copy link
Member Author

abidlabs commented Dec 6, 2024

Let me see if I can fix it real quick

@abidlabs
Copy link
Member Author

abidlabs commented Dec 6, 2024

Fixed the undo bug and added two more end-to-end tests to test. We've added quite a few e2e tests for chatinterface, but I think we need them all since there are so many different message types and configuration paths. When we have bandwidth, we can figure out ways to run them faster.

@abidlabs
Copy link
Member Author

abidlabs commented Dec 6, 2024

Thanks @freddyaboulton and @hysts for the thorough reviews, I'll merge this in when CI is green.

@abidlabs
Copy link
Member Author

abidlabs commented Dec 6, 2024

😅 taking a bit longer than I thought but doing some secondary cleanup as well

@abidlabs
Copy link
Member Author

abidlabs commented Dec 7, 2024

Whew finally ready. Will merge this in tomorrow if there are no objections!

@abidlabs abidlabs merged commit 48e4aa9 into main Dec 7, 2024
23 checks passed
@abidlabs abidlabs deleted the run-chi branch December 7, 2024 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
v: minor A change that requires a minor release
Projects
None yet
4 participants