Skip to content
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

Revert chatbot styling #8758

Merged
merged 8 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/nine-ways-sink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@gradio/chatbot": patch
"gradio": patch
---

fix:Revert chatbot styling
6 changes: 5 additions & 1 deletion demo/chatbot_with_tools/run.ipynb
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: chatbot_with_tools"]}, {"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", "from gradio import ChatMessage\n", "import time\n", "\n", "def generate_response(history):\n", " history.append(ChatMessage(role=\"user\", content=\"What is the weather in San Francisco right now?\"))\n", " yield history\n", " time.sleep(0.25)\n", " history.append(ChatMessage(role=\"assistant\",\n", " content=\"In order to find the current weather in San Francisco, I will need to use my weather tool.\")\n", " )\n", " yield history\n", " time.sleep(0.25)\n", "\n", " history.append(ChatMessage(role=\"assistant\",\n", " content=\"API Error when connecting to weather service.\",\n", " metadata={\"title\": \"\ud83d\udca5 Error using tool 'Weather'\"})\n", " )\n", " yield history\n", " time.sleep(0.25)\n", "\n", " history.append(ChatMessage(role=\"assistant\",\n", " content=\"I will try again\",\n", " ))\n", " yield history\n", " time.sleep(0.25)\n", "\n", " history.append(ChatMessage(role=\"assistant\",\n", " content=\"Weather 72 degrees Fahrenheit with 20% chance of rain.\",\n", " metadata={\"title\": \"\ud83d\udee0\ufe0f Used tool 'Weather'\"}\n", " ))\n", " yield history\n", " time.sleep(0.25)\n", "\n", " history.append(ChatMessage(role=\"assistant\",\n", " content=\"Now that the API succeeded I can complete my task.\",\n", " ))\n", " yield history\n", " time.sleep(0.25)\n", "\n", " history.append(ChatMessage(role=\"assistant\",\n", " content=\"It's a sunny day in San Francisco with a current temperature of 72 degrees Fahrenheit and a 20% chance of rain. Enjoy the weather!\",\n", " ))\n", " yield history\n", "\n", "\n", "with gr.Blocks() as demo:\n", " chatbot = gr.Chatbot(type=\"messages\")\n", " button = gr.Button(\"Get San Francisco Weather\")\n", " button.click(generate_response, chatbot, chatbot)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
<<<<<<< HEAD
{"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: chatbot_with_tools"]}, {"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", "from gradio import ChatMessage\n", "import time\n", "\n", "\n", "def generate_response(history):\n", " history.append(\n", " ChatMessage(\n", " role=\"user\", content=\"What is the weather in San Francisco right now?\"\n", " )\n", " )\n", " yield history\n", " time.sleep(0.25)\n", " history.append(\n", " ChatMessage(\n", " role=\"assistant\",\n", " content=\"In order to find the current weather in San Francisco, I will need to use my weather tool.\",\n", " )\n", " )\n", " yield history\n", " time.sleep(0.25)\n", "\n", " history.append(\n", " ChatMessage(\n", " role=\"assistant\",\n", " content=\"API Error when connecting to weather service.\",\n", " metadata={\"title\": \"\ud83d\udca5 Error using tool 'Weather'\"},\n", " )\n", " )\n", " yield history\n", " time.sleep(0.25)\n", "\n", " history.append(\n", " ChatMessage(\n", " role=\"assistant\",\n", " content=\"I will try again\",\n", " )\n", " )\n", " yield history\n", " time.sleep(0.25)\n", "\n", " history.append(\n", " ChatMessage(\n", " role=\"assistant\",\n", " content=\"Weather 72 degrees Fahrenheit with 20% chance of rain.\",\n", " metadata={\"title\": \"\ud83d\udee0\ufe0f Used tool 'Weather'\"},\n", " )\n", " )\n", " yield history\n", " time.sleep(0.25)\n", "\n", " history.append(\n", " ChatMessage(\n", " role=\"assistant\",\n", " content=\"Now that the API succeeded I can complete my task.\",\n", " )\n", " )\n", " yield history\n", " time.sleep(0.25)\n", "\n", " history.append(\n", " ChatMessage(\n", " role=\"assistant\",\n", " content=\"It's a sunny day in San Francisco with a current temperature of 72 degrees Fahrenheit and a 20% chance of rain. Enjoy the weather!\",\n", " )\n", " )\n", " yield history\n", "\n", "\n", "def like(evt: gr.LikeData):\n", " print(\"User liked the response\")\n", " print(evt.index, evt.liked, evt.value)\n", "\n", "\n", "with gr.Blocks() as demo:\n", " chatbot = gr.Chatbot(msg_format=\"messages\", height=500, show_copy_button=True)\n", " button = gr.Button(\"Get San Francisco Weather\")\n", " button.click(generate_response, chatbot, chatbot)\n", " chatbot.like(like)\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: chatbot_with_tools"]}, {"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", "from gradio import ChatMessage\n", "import time\n", "\n", "def generate_response(history):\n", " history.append(ChatMessage(role=\"user\", content=\"What is the weather in San Francisco right now?\"))\n", " yield history\n", " time.sleep(0.25)\n", " history.append(ChatMessage(role=\"assistant\",\n", " content=\"In order to find the current weather in San Francisco, I will need to use my weather tool.\")\n", " )\n", " yield history\n", " time.sleep(0.25)\n", "\n", " history.append(ChatMessage(role=\"assistant\",\n", " content=\"API Error when connecting to weather service.\",\n", " metadata={\"title\": \"\ud83d\udca5 Error using tool 'Weather'\"})\n", " )\n", " yield history\n", " time.sleep(0.25)\n", "\n", " history.append(ChatMessage(role=\"assistant\",\n", " content=\"I will try again\",\n", " ))\n", " yield history\n", " time.sleep(0.25)\n", "\n", " history.append(ChatMessage(role=\"assistant\",\n", " content=\"Weather 72 degrees Fahrenheit with 20% chance of rain.\",\n", " metadata={\"title\": \"\ud83d\udee0\ufe0f Used tool 'Weather'\"}\n", " ))\n", " yield history\n", " time.sleep(0.25)\n", "\n", " history.append(ChatMessage(role=\"assistant\",\n", " content=\"Now that the API succeeded I can complete my task.\",\n", " ))\n", " yield history\n", " time.sleep(0.25)\n", "\n", " history.append(ChatMessage(role=\"assistant\",\n", " content=\"It's a sunny day in San Francisco with a current temperature of 72 degrees Fahrenheit and a 20% chance of rain. Enjoy the weather!\",\n", " ))\n", " yield history\n", "\n", "\n", "with gr.Blocks() as demo:\n", " chatbot = gr.Chatbot(type=\"messages\")\n", " button = gr.Button(\"Get San Francisco Weather\")\n", " button.click(generate_response, chatbot, chatbot)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
>>>>>>> main
73 changes: 51 additions & 22 deletions demo/chatbot_with_tools/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,52 +2,81 @@
from gradio import ChatMessage
import time


def generate_response(history):
history.append(ChatMessage(role="user", content="What is the weather in San Francisco right now?"))
history.append(
ChatMessage(
role="user", content="What is the weather in San Francisco right now?"
)
)
yield history
time.sleep(0.25)
history.append(ChatMessage(role="assistant",
content="In order to find the current weather in San Francisco, I will need to use my weather tool.")
)
history.append(
ChatMessage(
role="assistant",
content="In order to find the current weather in San Francisco, I will need to use my weather tool.",
)
)
yield history
time.sleep(0.25)

history.append(ChatMessage(role="assistant",
content="API Error when connecting to weather service.",
metadata={"title": "💥 Error using tool 'Weather'"})
)
history.append(
ChatMessage(
role="assistant",
content="API Error when connecting to weather service.",
metadata={"title": "💥 Error using tool 'Weather'"},
)
)
yield history
time.sleep(0.25)

history.append(ChatMessage(role="assistant",
content="I will try again",
))
history.append(
ChatMessage(
role="assistant",
content="I will try again",
)
)
yield history
time.sleep(0.25)

history.append(ChatMessage(role="assistant",
content="Weather 72 degrees Fahrenheit with 20% chance of rain.",
metadata={"title": "🛠️ Used tool 'Weather'"}
))
history.append(
ChatMessage(
role="assistant",
content="Weather 72 degrees Fahrenheit with 20% chance of rain.",
metadata={"title": "🛠️ Used tool 'Weather'"},
)
)
yield history
time.sleep(0.25)

history.append(ChatMessage(role="assistant",
content="Now that the API succeeded I can complete my task.",
))
history.append(
ChatMessage(
role="assistant",
content="Now that the API succeeded I can complete my task.",
)
)
yield history
time.sleep(0.25)

history.append(ChatMessage(role="assistant",
content="It's a sunny day in San Francisco with a current temperature of 72 degrees Fahrenheit and a 20% chance of rain. Enjoy the weather!",
))
history.append(
ChatMessage(
role="assistant",
content="It's a sunny day in San Francisco with a current temperature of 72 degrees Fahrenheit and a 20% chance of rain. Enjoy the weather!",
)
)
yield history


def like(evt: gr.LikeData):
print("User liked the response")
print(evt.index, evt.liked, evt.value)


with gr.Blocks() as demo:
chatbot = gr.Chatbot(type="messages")
chatbot = gr.Chatbot(type="messages", height=500, show_copy_button=True)
button = gr.Button("Get San Francisco Weather")
button.click(generate_response, chatbot, chatbot)
chatbot.like(like)

if __name__ == "__main__":
demo.launch()
8 changes: 5 additions & 3 deletions gradio/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,11 @@ def set_cancel_events(

root_block.set_event_trigger(
triggers,
fn=lambda: [Timer(active=False) for _ in timers_to_cancel]
if len(timers_to_cancel) > 1
else Timer(active=False),
fn=lambda: (
[Timer(active=False) for _ in timers_to_cancel]
if len(timers_to_cancel) > 1
else Timer(active=False)
),
inputs=None,
outputs=timers_to_cancel,
show_api=False,
Expand Down
1 change: 1 addition & 0 deletions js/chatbot/Index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
upload={gradio.client.upload}
_fetch={gradio.client.fetch}
load_component={gradio.load_component}
{msg_format}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think needs to be msg_format={type} because I renamed to type

/>
</div>
</Block>
Expand Down
30 changes: 16 additions & 14 deletions js/chatbot/shared/ButtonPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</span>
</DownloadLink>
{/if}
{#if likeable && position === "left"}
{#if likeable}
<LikeDislike {handle_action} padded={show_copy || show_download} />
{/if}
</div>
Expand All @@ -54,36 +54,34 @@
.icon-wrap:hover {
color: var(--body-text-color);
}
.message-buttons-right,
.message-buttons-left {

.message-buttons {
border-radius: var(--radius-md);
display: flex;
align-items: center;
bottom: 0;

height: var(--size-7);
align-self: self-end;
/* position: absolute; */
bottom: -15px;
margin: 2px;
margin: 0px calc(var(--spacing-xl) * 3);
padding-left: 5px;
z-index: 1;
padding-bottom: var(--spacing-xl);
padding: var(--spacing-md) 2px;
padding: var(--spacing-md) var(--spacing-md);
border: 1px solid var(--border-color-primary);
background: var(--border-color-secondary);
gap: var(--spacing-md);
}
.message-buttons-left {
align-self: start;
left: 0px;
}
.message-buttons-right {
right: 5px;
}

.panel.message-buttons-left,
.panel.message-buttons-right {
margin: 10px 0 2px 0;
}

.message-buttons {
/* .message-buttons {
left: 0px;
right: 0px;
top: unset;
Expand All @@ -92,9 +90,13 @@
justify-content: flex-start;
align-items: center;
gap: 0px;
}
} */

.message-buttons :global(> *) {
margin-right: 7px;
margin-right: 0px;
}

.with-avatar {
margin-left: calc(var(--spacing-xl) * 4 + 31px);
}
</style>
Loading
Loading