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
Like/Dislike Button for Chatbot #5391
Conversation
🪼 branch checks and previews
Install Gradio from this PR pip install https://gradio-builds.s3.amazonaws.com/af6314364b152c5594c83ef9f4ff9c4df358b460/gradio-3.41.2-py3-none-any.whl Install Gradio Python Client from this PR pip install "gradio-client @ git+https://github.com/gradio-app/gradio@af6314364b152c5594c83ef9f4ff9c4df358b460#subdirectory=client/python" |
🦄 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.
|
Works very nicely @dawoodkhan82! In terms of the UI, are you thinking of putting the icons in the top right, similar to the copy button? |
@Shelliemayinforest Currently fixing the UI. |
@abidlabs ready for re-review |
Did something happen to the height of the chatbot bubbles @dawoodkhan82? I'm seeing this for a regular Chatbot: And this is how the likable chatbot looks: Test code: import gradio as gr
def test(x: gr.LikeData):
print(x.index, x.value, x.liked)
with gr.Blocks() as demo:
c = gr.Chatbot([("abc", "def"), ("egh", "ijk")])
c.like(test, None, None)
demo.launch() |
Finally, it would be great to add an example of how to use the Maybe we could add a section right after streaming in this Guide? https://www.gradio.app/guides/creating-a-custom-chatbot-with-blocks |
Ah yeah I did mess up the height. Was testing with the copy button enabled. Will address in a bit |
@abidlabs Ok the UI should be good now |
@abidlabs Will update the guide in a separate PR |
LGTM @dawoodkhan82! I added a small section in our Chatbot guide for now -- though feel free to edit or expand it. |
How about adding a labeling field which accept comments similar to the like and dislike button? |
Hi @jeffchy you could add a |
How do I store the like value in a json or yaml file? As of now, I think the like/unlike can only be clicked and it doesn't do anything else, am I right? What if I want to record the user preferences somewhere? |
Hi @PrashantSaikia, you can run arbitrary code (such as logging to a csv) within the function that is attached to the import gradio as gr
def test(x: gr.LikeData):
print(x.index, x.value, x.liked)
with gr.Blocks() as demo:
c = gr.Chatbot([("abc", "def"), ("egh", "ijk")])
c.like(test, None, None)
demo.launch() |
Hi @abidlabs, The problem with the |
If I understand correctly, you should be able to achieve this by also passing the chatbot as an input to your import gradio as gr
def test(x: gr.LikeData, history):
print(x.index, x.value, x.liked)
print(history)
with gr.Blocks() as demo:
c = gr.Chatbot([("abc", "def"), ("egh", "ijk")])
c.like(test, c, None)
demo.launch() |
You could save the chatbot history to a file every time the chatbot runs, and then create a |
With this, there is no way to know what was the query whose response was being upvoted or downvoted, right? That's what I want to be added, I guess some kind of handle would need to be there that shows which user query precedes the chatbot response. Am I correct or is it already there? |
Hi @PrashantSaikia you can get the query by looking at the index -- x.index will be something like [3, 1], which means the bot response (1) to the 4th message (since 0-indexed). If you look at the |
Ah, ok, got it now. So its these then:
|
Yes that looks right |
Description
Adds like/dislike events trigger and buttons for chatbot messages
Here's an example of how to use the "Like" event trigger:
Closes: #5250
🎯 PRs Should Target Issues
Before your create a PR, please check to see if there is an existing issue for this change. If not, please create an issue before you create this PR, unless the fix is very small.
Not adhering to this guideline will result in the PR being closed.
Tests
PRs will only be merged if tests pass on CI. To run the tests locally, please set up your Gradio environment locally and run the tests:
bash scripts/run_all_tests.sh
You may need to run the linters:
bash scripts/format_backend.sh
andbash scripts/format_frontend.sh