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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

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
🦄 Changes detected! Details

Install Gradio from this PR

pip install https://gradio-pypi-previews.s3.amazonaws.com/cf14b235be91922dadc22439a73ec6d44a080ee6/gradio-5.7.1-py3-none-any.whl

Install Gradio Python Client from this PR

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

Install Gradio JS Client from this PR

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

Use Lite from this PR

<script type="module" src="https://gradio-lite-previews.s3.amazonaws.com/cf14b235be91922dadc22439a73ec6d44a080ee6/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
  • 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()

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
3 participants