-
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
Support saving chat history in gr.ChatInterface
#10191
Merged
Merged
Changes from 78 commits
Commits
Show all changes
85 commits
Select commit
Hold shift + click to select a range
b6bca34
save history prototype
abidlabs a846b38
add changeset
gradio-pr-bot d8d64bc
merge
dawoodkhan82 dfd3ad5
Merge branch 'main' into chat-history
abidlabs 4572a74
Declare exports in __all__ for type checking (#10238)
dustalov bcd383e
Add `gr.BrowserState` change event (#10245)
abidlabs a1e0bd1
history
dawoodkhan82 02caf94
Merge branch 'main' into chat-history
dawoodkhan82 8ace831
Merge branch 'main' into chat-history
abidlabs be531b6
Merge branch 'chat-history' of github.com:gradio-app/gradio into chat…
abidlabs caccb0b
changes
abidlabs 9251dea
changes
abidlabs 08e6615
changes
abidlabs 3cdb67b
history
abidlabs c20ceda
changes
abidlabs 8438764
changes
abidlabs 269ff00
changes
abidlabs 5477552
format
abidlabs a51cbef
add changeset
gradio-pr-bot d8ca538
Merge branch 'main' into chat-history
abidlabs 59baf96
changes
abidlabs 25558a0
changes
abidlabs ea42b9e
more changes
abidlabs 95b49fb
changes
abidlabs 99bb7df
dataset changes
abidlabs 7a6a8b7
changes
abidlabs 2580513
add changeset
gradio-pr-bot 9ce023f
add md variant for button
abidlabs dac913b
Merge branch 'chat-history' of github.com:gradio-app/gradio into chat…
abidlabs 4e3a537
add changeset
gradio-pr-bot 464db2b
changes
abidlabs 690912e
changes
abidlabs 303be42
format
abidlabs 8b7cc0e
format
abidlabs 11c34c3
add changeset
gradio-pr-bot 21aa096
changes
abidlabs 9d76b7d
Merge branch 'chat-history' of github.com:gradio-app/gradio into chat…
abidlabs a2b7542
changes
abidlabs b7357c1
more changes
abidlabs 7987774
changes
abidlabs 89e5c71
changes
abidlabs 51e1daa
add changeset
gradio-pr-bot d95022b
changes
abidlabs 5ec7613
Merge branch 'chat-history' of github.com:gradio-app/gradio into chat…
abidlabs 86f4432
docs
abidlabs d18879b
changes
abidlabs 7c4a8e3
changes
abidlabs af6523e
changes
abidlabs 037b1e9
changes
abidlabs ded0b3d
fix
abidlabs 7cbc66f
fix tests
abidlabs 37f4a84
change
abidlabs 6e90ca3
add changeset
gradio-pr-bot bff664e
fix logo issue
abidlabs 0ec7f25
Merge branch 'chat-history' of github.com:gradio-app/gradio into chat…
abidlabs 6842fa5
changes
abidlabs 5052e5d
version
abidlabs 791deca
add changeset
gradio-pr-bot 59bcf92
fix typecheck
abidlabs 67770ec
Merge branch 'chat-history' of github.com:gradio-app/gradio into chat…
abidlabs ddbe6a8
remove redundant
abidlabs 92e905e
pkg version
abidlabs 9075df8
add changeset
gradio-pr-bot 13bfe8c
changes
abidlabs 42a4333
Merge branch 'chat-history' of github.com:gradio-app/gradio into chat…
abidlabs 32bed0d
Revert "changes"
abidlabs 48093c1
reorganize code
abidlabs edeb035
format
abidlabs abb8a8e
changes
abidlabs df7c388
add to deployed demos
abidlabs 9e79e86
fix icons
abidlabs 4fe0eaf
fix icon
abidlabs 993b84e
Merge branch 'main' into chat-history
abidlabs b63a9bb
lint
abidlabs 49be8b0
changes
abidlabs bcb7bc2
Merge branch 'chat-history' of github.com:gradio-app/gradio into chat…
abidlabs eaeb078
Merge branch 'main' into chat-history
abidlabs fc00a7d
example
abidlabs 14f4899
changes
abidlabs 25b590c
fix buttons
abidlabs 01363e2
add changeset
gradio-pr-bot 1d9fb13
format
abidlabs ba3d100
add changeset
gradio-pr-bot 45deb34
update icon
abidlabs f136fec
Merge branch 'chat-history' of github.com:gradio-app/gradio into chat…
abidlabs 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,8 @@ | ||
--- | ||
"@gradio/button": minor | ||
"@gradio/dataset": minor | ||
"@gradio/textbox": minor | ||
"gradio": minor | ||
--- | ||
|
||
feat:Support saving chat history in `gr.ChatInterface` |
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 @@ | ||
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: chatinterface_save_history"]}, {"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 gradio as gr\n", "\n", "def echo_multimodal(message, history):\n", " response = \"You wrote: '\" + message[\"text\"] + \"' and uploaded: \" + str(len(message[\"files\"])) + \" files\"\n", " return response\n", "\n", "demo = gr.ChatInterface(\n", " echo_multimodal,\n", " type=\"messages\",\n", " multimodal=True,\n", " textbox=gr.MultimodalTextbox(file_count=\"multiple\"),\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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import gradio as gr | ||
|
||
def echo_multimodal(message, history): | ||
response = "You wrote: '" + message["text"] + "' and uploaded: " + str(len(message["files"])) + " files" | ||
return response | ||
|
||
demo = gr.ChatInterface( | ||
echo_multimodal, | ||
type="messages", | ||
multimodal=True, | ||
textbox=gr.MultimodalTextbox(file_count="multiple"), | ||
save_history=True, | ||
) | ||
|
||
if __name__ == "__main__": | ||
demo.launch() |
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(slow_echo, type=\"messages\", flagging_mode=\"manual\", flagging_options=[\"Like\", \"Spam\", \"Inappropriate\", \"Other\"])\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(slow_echo, type=\"messages\", save_history=True)\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
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,11 +29,13 @@ def __init__( | |
self, | ||
*, | ||
label: str | None = None, | ||
show_label: bool = True, | ||
components: Sequence[Component] | list[str] | None = None, | ||
component_props: list[dict[str, Any]] | None = None, | ||
samples: list[list[Any]] | None = None, | ||
headers: list[str] | None = None, | ||
type: Literal["values", "index", "tuple"] = "values", | ||
layout: Literal["gallery", "table"] | None = None, | ||
samples_per_page: int = 10, | ||
visible: bool = True, | ||
elem_id: str | None = None, | ||
|
@@ -49,10 +51,12 @@ def __init__( | |
""" | ||
Parameters: | ||
label: the label for this component, appears above the component. | ||
show_label: If True, the label will be shown above the component. | ||
components: Which component types to show in this dataset widget, can be passed in as a list of string names or Components instances. The following components are supported in a Dataset: Audio, Checkbox, CheckboxGroup, ColorPicker, Dataframe, Dropdown, File, HTML, Image, Markdown, Model3D, Number, Radio, Slider, Textbox, TimeSeries, Video | ||
samples: a nested list of samples. Each sublist within the outer list represents a data sample, and each element within the sublist represents an value for each component | ||
headers: Column headers in the Dataset widget, should be the same len as components. If not provided, inferred from component labels | ||
type: "values" if clicking on a sample should pass the value of the sample, "index" if it should pass the index of the sample, or "tuple" if it should pass both the index and the value of the sample. | ||
layout: "gallery" if the dataset should be displayed as a gallery with each sample in a clickable card, or "table" if it should be displayed as a table with each sample in a row. By default, "gallery" is used if there is a single component, and "table" is used if there are more than one component. If there are more than one component, the layout can only be "table". | ||
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. I added some parameters to |
||
samples_per_page: how many examples to show per page. | ||
visible: If False, component will be hidden. | ||
elem_id: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles. | ||
|
@@ -75,6 +79,8 @@ def __init__( | |
self.container = container | ||
self.scale = scale | ||
self.min_width = min_width | ||
self.layout = layout | ||
self.show_label = show_label | ||
self._components = [get_component_instance(c) for c in components or []] | ||
if component_props is None: | ||
self.component_props = [ | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
The icons in this directory are loaded via `gradio.utils.get_icon_path` and | ||
can be used directly in backend code (e.g. to populate icons in components). |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Oops, something went wrong.
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.
I added a "md"-sized button as that was ideal for this UI and I think it could be more broadly useful.
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.
Made the same change to all of the subclasses of Button below