-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Reset flagged values when switching conversations in chat history #10292
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
ccb06da
chat history
abidlabs 8127835
add changeset
gradio-pr-bot 498330f
changes
abidlabs df28aa2
Merge branch 'history-flag' of github.com:gradio-app/gradio into hist…
abidlabs 1dba888
add changeset
gradio-pr-bot 5746c29
changes
abidlabs 4c6b103
Merge branch 'history-flag' of github.com:gradio-app/gradio into hist…
abidlabs 6b359f4
changes
abidlabs f8a3f6e
more changes
abidlabs 6c30eb3
changes
abidlabs 840d285
changes
abidlabs e5a722a
format
abidlabs 0a94466
notebook
abidlabs 4ca1148
fix test
abidlabs 54c36f0
changes
2ed11a2
add changeset
gradio-pr-bot 318742e
changes
abidlabs 979ce63
Merge branch 'history-flag' of github.com:gradio-app/gradio into hist…
abidlabs 2e88435
changes
abidlabs c0f2163
Merge branch 'main' into history-flag
abidlabs 2199d58
changes
abidlabs 253758b
Merge branch 'history-flag' of github.com:gradio-app/gradio into hist…
abidlabs 1485016
add changeset
gradio-pr-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
"@gradio/atoms": minor | ||
"@gradio/chatbot": minor | ||
"gradio": minor | ||
--- | ||
|
||
feat:Reset flagged values when switching conversations in chat history |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: chatinterface_streaming_echo"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import time\n", "import gradio as gr\n", "\n", "def slow_echo(message, history):\n", " for i in range(len(message)):\n", " time.sleep(0.05)\n", " yield \"You typed: \" + message[: i + 1]\n", "\n", "demo = gr.ChatInterface(\n", " slow_echo,\n", " type=\"messages\",\n", " flagging_mode=\"manual\",\n", " flagging_options=[\"Like\", \"Spam\", \"Inappropriate\", \"Other\"], \n", " save_history=True,\n", ")\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5} | ||
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: chatinterface_streaming_echo"]}, {"cell_type": "code", "execution_count": null, "id": "272996653310673477252411125948039410165", "metadata": {}, "outputs": [], "source": ["!pip install -q gradio "]}, {"cell_type": "code", "execution_count": null, "id": "288918539441861185822528903084949547379", "metadata": {}, "outputs": [], "source": ["import time\n", "import gradio as gr\n", "\n", "def slow_echo(message, history):\n", " for i in range(len(message)):\n", " time.sleep(0.05)\n", " yield \"You typed: \" + message[: i + 1]\n", "\n", "demo = gr.ChatInterface(\n", " slow_echo,\n", " type=\"messages\",\n", " flagging_mode=\"manual\",\n", " flagging_options=[\"Like\", \"Spam\", \"Inappropriate\", \"Other\"],\n", " save_history=True,\n", ")\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -249,7 +249,7 @@ def __init__( | |
|
||
with self: | ||
self.saved_conversations = BrowserState( | ||
[], storage_key="_saved_conversations" | ||
[], storage_key=f"_saved_conversations_{self._id}" | ||
) | ||
self.conversation_id = State(None) | ||
self.saved_input = State() # Stores the most recent user message | ||
|
@@ -279,7 +279,7 @@ def _render_history_area(self): | |
with Column(scale=1, min_width=100): | ||
self.new_chat_button = Button( | ||
"New chat", | ||
variant="secondary", | ||
variant="primary", | ||
size="md", | ||
icon=utils.get_icon_path("plus.svg"), | ||
) | ||
|
@@ -467,6 +467,28 @@ def _delete_conversation( | |
saved_conversations.pop(index) | ||
return None, saved_conversations | ||
|
||
def _load_chat_history(self, conversations): | ||
return Dataset( | ||
samples=[ | ||
[self._generate_chat_title(conv)] | ||
for conv in conversations or [] | ||
if conv | ||
] | ||
) | ||
|
||
def _load_conversation( | ||
self, | ||
index: int, | ||
conversations: list[list[MessageDict]], | ||
): | ||
return ( | ||
index, | ||
Chatbot( | ||
value=conversations[index], # type: ignore | ||
feedback_value=[], | ||
), | ||
) | ||
|
||
def _setup_events(self) -> None: | ||
from gradio import on | ||
|
||
|
@@ -645,28 +667,29 @@ def _setup_events(self) -> None: | |
queue=False, | ||
) | ||
|
||
@on( | ||
[self.load, self.saved_conversations.change], | ||
on( | ||
triggers=[self.load, self.saved_conversations.change], | ||
fn=self._load_chat_history, | ||
inputs=[self.saved_conversations], | ||
outputs=[self.chat_history_dataset], | ||
show_api=False, | ||
queue=False, | ||
) | ||
def load_chat_history(conversations): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Decided to avoid using decorator syntax for consistency with the rest of the file |
||
return Dataset( | ||
samples=[ | ||
[self._generate_chat_title(conv)] | ||
for conv in conversations or [] | ||
if conv | ||
] | ||
) | ||
|
||
self.chat_history_dataset.click( | ||
lambda index, conversations: (index, conversations[index]), | ||
lambda: [], | ||
None, | ||
[self.chatbot], | ||
show_api=False, | ||
queue=False, | ||
show_progress="hidden", | ||
).then( | ||
self._load_conversation, | ||
[self.chat_history_dataset, self.saved_conversations], | ||
[self.conversation_id, self.chatbot], | ||
show_api=False, | ||
queue=False, | ||
show_progress="hidden", | ||
).then(**synchronize_chat_state_kwargs) | ||
|
||
if self.flagging_mode != "never": | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Adds a
self._id
in case your Gradio app has multiplegr.ChatInterface
-s