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

Allow supplying custom gr.Chatbot with events to gr.ChatInterface #8677

Merged
merged 13 commits into from
Jul 2, 2024

Conversation

abidlabs
Copy link
Member

@abidlabs abidlabs commented Jul 1, 2024

Fixes: #8675 so that now you can put a gr.ChatInterface inside a gr.Blocks with a custom gr.Chatbot and attach events, like this:

import gradio as gr

def vote(data: gr.LikeData):
    print(data.value)
    if data.liked:
        print("You upvoted this response: " + data.value["value"])
    else:
        print("You downvoted this response: " + data.value["value"])

with gr.Blocks() as demo:
    chatbot = gr.Chatbot()
    chatbot.like(vote, None, None)
    gr.ChatInterface(fn=lambda x,y:x, chatbot=chatbot)
    
demo.launch()

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Jul 1, 2024

🪼 branch checks and previews

Name Status URL
Spaces ready! Spaces preview
Website ready! Website preview
Storybook ready! Storybook preview
🦄 Changes detecting...

Install Gradio from this PR

pip install https://gradio-builds.s3.amazonaws.com/65dc93b2bdc1eca41daa08cbca588de1f0c10b8b/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@65dc93b2bdc1eca41daa08cbca588de1f0c10b8b#subdirectory=client/python"

Install Gradio JS Client from this PR

npm install https://gradio-builds.s3.amazonaws.com/65dc93b2bdc1eca41daa08cbca588de1f0c10b8b/gradio-client-1.2.1.tgz

@gradio-pr-bot
Copy link
Collaborator

gradio-pr-bot commented Jul 1, 2024

🦄 change detected

This Pull Request includes changes to the following packages.

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

With the following changelog entry.

Allow supplying custom gr.Chatbot with events to gr.ChatInterface

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 marked this pull request as ready for review July 1, 2024 13:45
@abidlabs abidlabs changed the title Chatinterface like Allow putting suppling custom gr.Chatbot with events to gr.ChatInterface Jul 1, 2024
Copy link
Collaborator

@freddyaboulton freddyaboulton left a comment

Choose a reason for hiding this comment

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

Nice fix @abidlabs !

@@ -136,6 +136,25 @@ gr.ChatInterface(

The placeholder appears vertically and horizontally centered in the chatbot.

If you would like to attach event listeners to your custom chatbot, wrap the chatbot as well as the `gr.ChatInterface` inside of a `gr.Blocks` like this:
Copy link
Collaborator

Choose a reason for hiding this comment

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

feel like the "creating a chatbot fast" guide should be quick and sweet, this particular usecase doesn't seem common enough to be here.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's fair, this guide is getting quite bloated. It would be better to move this over to the docs page for gr.ChatInterface. Let me do that

Copy link
Collaborator

@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!

@abidlabs abidlabs changed the title Allow putting suppling custom gr.Chatbot with events to gr.ChatInterface Allow supplying custom gr.Chatbot with events to gr.ChatInterface Jul 2, 2024
@abidlabs abidlabs merged commit c946c6f into main Jul 2, 2024
8 checks passed
@abidlabs abidlabs deleted the chatinterface-like branch July 2, 2024 18:13
@abidlabs
Copy link
Member Author

abidlabs commented Jul 2, 2024

Thanks folks!

@pngwn pngwn mentioned this pull request Jul 2, 2024
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.

Error when passing in a custom chatbot to add like/dislike feature to Chatinterface
4 participants