Skip to content

Commit 5ce2832

Browse files
abidlabsgradio-pr-botdawoodkhan82dustalovfreddyaboulton
authored
Support saving chat history in gr.ChatInterface (#10191)
* save history prototype * add changeset * Declare exports in __all__ for type checking (#10238) * Declare exports * add changeset * type fixes * more type fixes * add changeset * notebooks * changes --------- Co-authored-by: gradio-pr-bot <[email protected]> Co-authored-by: Freddy Boulton <[email protected]> Co-authored-by: Abubakar Abid <[email protected]> * Add `gr.BrowserState` change event (#10245) * changes * changes * add changeset * format * changes --------- Co-authored-by: gradio-pr-bot <[email protected]> * history * changes * changes * changes * history * changes * changes * changes * format * add changeset * changes * changes * more changes * changes * dataset changes * changes * add changeset * add md variant for button * add changeset * changes * changes * format * format * add changeset * changes * changes * more changes * changes * changes * add changeset * changes * docs * changes * changes * changes * changes * fix * fix tests * change * add changeset * fix logo issue * changes * version * add changeset * fix typecheck * remove redundant * pkg version * add changeset * changes * Revert "changes" This reverts commit 13bfe8c. * reorganize code * format * changes * add to deployed demos * fix icons * fix icon * lint * changes * example * changes * fix buttons * add changeset * format * add changeset * update icon --------- Co-authored-by: gradio-pr-bot <[email protected]> Co-authored-by: Dawood <[email protected]> Co-authored-by: Dmitry Ustalov <[email protected]> Co-authored-by: Freddy Boulton <[email protected]>
1 parent a1f2649 commit 5ce2832

30 files changed

+484
-163
lines changed

.changeset/tiny-areas-train.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
"@gradio/button": minor
3+
"@gradio/chatbot": minor
4+
"@gradio/dataset": minor
5+
"@gradio/downloadbutton": minor
6+
"@gradio/textbox": minor
7+
"@gradio/uploadbutton": minor
8+
"gradio": minor
9+
---
10+
11+
feat:Support saving chat history in `gr.ChatInterface`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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}
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import gradio as gr
2+
3+
def echo_multimodal(message, history):
4+
response = "You wrote: '" + message["text"] + "' and uploaded: " + str(len(message["files"])) + " files"
5+
return response
6+
7+
demo = gr.ChatInterface(
8+
echo_multimodal,
9+
type="messages",
10+
multimodal=True,
11+
textbox=gr.MultimodalTextbox(file_count="multiple"),
12+
save_history=True,
13+
)
14+
15+
if __name__ == "__main__":
16+
demo.launch()
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +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}
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}

demo/chatinterface_streaming_echo/run.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@ def slow_echo(message, history):
66
time.sleep(0.05)
77
yield "You typed: " + message[: i + 1]
88

9-
demo = gr.ChatInterface(slow_echo, type="messages", flagging_mode="manual", flagging_options=["Like", "Spam", "Inappropriate", "Other"])
9+
demo = gr.ChatInterface(
10+
slow_echo,
11+
type="messages",
12+
flagging_mode="manual",
13+
flagging_options=["Like", "Spam", "Inappropriate", "Other"],
14+
save_history=True,
15+
)
1016

1117
if __name__ == "__main__":
1218
demo.launch()

gradio/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@
167167
"ImageEditor",
168168
"ImageMask",
169169
"Info",
170-
"Success",
171170
"Interface",
172171
"JSON",
173172
"Json",
@@ -204,6 +203,7 @@
204203
"Sketchpad",
205204
"Slider",
206205
"State",
206+
"Success",
207207
"Tab",
208208
"TabItem",
209209
"TabbedInterface",

0 commit comments

Comments
 (0)