Skip to content

Commit

Permalink
Support saving chat history in gr.ChatInterface (#10191)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
5 people authored Jan 4, 2025
1 parent a1f2649 commit 5ce2832
Show file tree
Hide file tree
Showing 30 changed files with 484 additions and 163 deletions.
11 changes: 11 additions & 0 deletions .changeset/tiny-areas-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
"@gradio/button": minor
"@gradio/chatbot": minor
"@gradio/dataset": minor
"@gradio/downloadbutton": minor
"@gradio/textbox": minor
"@gradio/uploadbutton": minor
"gradio": minor
---

feat:Support saving chat history in `gr.ChatInterface`
1 change: 1 addition & 0 deletions demo/chatinterface_save_history/run.ipynb
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}
16 changes: 16 additions & 0 deletions demo/chatinterface_save_history/run.py
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()
2 changes: 1 addition & 1 deletion demo/chatinterface_streaming_echo/run.ipynb
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(\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}
8 changes: 7 additions & 1 deletion demo/chatinterface_streaming_echo/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ def slow_echo(message, history):
time.sleep(0.05)
yield "You typed: " + message[: i + 1]

demo = gr.ChatInterface(slow_echo, type="messages", flagging_mode="manual", flagging_options=["Like", "Spam", "Inappropriate", "Other"])
demo = gr.ChatInterface(
slow_echo,
type="messages",
flagging_mode="manual",
flagging_options=["Like", "Spam", "Inappropriate", "Other"],
save_history=True,
)

if __name__ == "__main__":
demo.launch()
2 changes: 1 addition & 1 deletion gradio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@
"ImageEditor",
"ImageMask",
"Info",
"Success",
"Interface",
"JSON",
"Json",
Expand Down Expand Up @@ -204,6 +203,7 @@
"Sketchpad",
"Slider",
"State",
"Success",
"Tab",
"TabItem",
"TabbedInterface",
Expand Down
Loading

0 comments on commit 5ce2832

Please sign in to comment.