-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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 additional_outputs
in gr.ChatInterface
#10071
Merged
+222
−115
Merged
Changes from all commits
Commits
Show all changes
33 commits
Select commit
Hold shift + click to select a range
4d1a468
artifacts
abidlabs fffe8bb
add changeset
gradio-pr-bot b4e3868
chatinterface
abidlabs afcf979
Merge branch 'additional-outputs' of github.com:gradio-app/gradio int…
abidlabs c34f43e
guide fixes
abidlabs ab6e6b9
example
abidlabs 4d7b588
zerogpu
abidlabs 64f7d0d
Revert "zerogpu"
abidlabs c09a446
changes
abidlabs db63a22
submit fn
abidlabs a5bcbba
chat interface
abidlabs 6865a97
Merge branch 'main' into additional-outputs
abidlabs 31cac4c
changes
abidlabs c43a4c5
Merge branch 'additional-outputs' of github.com:gradio-app/gradio int…
abidlabs 5d448ba
add changeset
gradio-pr-bot 1eb09df
notebook
abidlabs 4b21b70
Merge branch 'additional-outputs' of github.com:gradio-app/gradio int…
abidlabs 7d4f45a
lint
abidlabs ffd25ca
type
abidlabs 67ad26b
Merge branch 'main' into additional-outputs
abidlabs eacc2fd
changes
abidlabs 29b8d55
regex
abidlabs eb3ddd3
add changeset
gradio-pr-bot 89e7ac4
fixes
abidlabs d6ced3e
Merge branch 'additional-outputs' of github.com:gradio-app/gradio int…
abidlabs 8f81da7
line
abidlabs 0faef73
fixes
abidlabs df18abd
formatting
abidlabs 0b0433f
change
abidlabs dfc7bcb
change
abidlabs 93a0638
add guard
abidlabs fe603f9
link to playground demo
aliabd 591dcd0
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,6 @@ | ||
--- | ||
"gradio": minor | ||
"website": minor | ||
--- | ||
|
||
feat:Support `additional_outputs` 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_artifacts"]}, {"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", "python_code = \"\"\"\n", "def fib(n):\n", " if n <= 0:\n", " return 0\n", " elif n == 1:\n", " return 1\n", " else:\n", " return fib(n-1) + fib(n-2)\n", "\"\"\"\n", "\n", "js_code = \"\"\"\n", "function fib(n) {\n", " if (n <= 0) return 0;\n", " if (n === 1) return 1;\n", " return fib(n - 1) + fib(n - 2);\n", "}\n", "\"\"\"\n", "\n", "def chat(message, history):\n", " if \"python\" in message.lower():\n", " return \"Type Python or JavaScript to see the code.\", gr.Code(language=\"python\", value=python_code)\n", " elif \"javascript\" in message.lower():\n", " return \"Type Python or JavaScript to see the code.\", gr.Code(language=\"javascript\", value=js_code)\n", " else:\n", " return \"Please ask about Python or JavaScript.\", None\n", "\n", "with gr.Blocks() as demo:\n", " code = gr.Code(render=False)\n", " with gr.Row():\n", " with gr.Column():\n", " gr.Markdown(\"<center><h1>Write Python or JavaScript</h1></center>\")\n", " gr.ChatInterface(\n", " chat,\n", " examples=[\"Python\", \"JavaScript\"],\n", " additional_outputs=[code],\n", " type=\"messages\"\n", " )\n", " with gr.Column():\n", " gr.Markdown(\"<center><h1>Code Artifacts</h1></center>\")\n", " code.render()\n", "\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,44 @@ | ||
import gradio as gr | ||
|
||
python_code = """ | ||
def fib(n): | ||
if n <= 0: | ||
return 0 | ||
elif n == 1: | ||
return 1 | ||
else: | ||
return fib(n-1) + fib(n-2) | ||
""" | ||
|
||
js_code = """ | ||
function fib(n) { | ||
if (n <= 0) return 0; | ||
if (n === 1) return 1; | ||
return fib(n - 1) + fib(n - 2); | ||
} | ||
""" | ||
|
||
def chat(message, history): | ||
if "python" in message.lower(): | ||
return "Type Python or JavaScript to see the code.", gr.Code(language="python", value=python_code) | ||
elif "javascript" in message.lower(): | ||
return "Type Python or JavaScript to see the code.", gr.Code(language="javascript", value=js_code) | ||
else: | ||
return "Please ask about Python or JavaScript.", None | ||
|
||
with gr.Blocks() as demo: | ||
code = gr.Code(render=False) | ||
with gr.Row(): | ||
with gr.Column(): | ||
gr.Markdown("<center><h1>Write Python or JavaScript</h1></center>") | ||
gr.ChatInterface( | ||
chat, | ||
examples=["Python", "JavaScript"], | ||
additional_outputs=[code], | ||
type="messages" | ||
) | ||
with gr.Column(): | ||
gr.Markdown("<center><h1>Code Artifacts</h1></center>") | ||
code.render() | ||
|
||
demo.launch() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# How to Create a Chatbot with Gradio | ||
|
||
Tags: NLP, LLM, CHATBOT | ||
Tags: LLM, CHATBOT, NLP | ||
|
||
## Introduction | ||
|
||
|
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.
Cool that it handles reqs as well!