jedick
Add link to issue
284ee47
import gradio as gr
import time
# Inspired by: https://www.gradio.app/guides/agents-and-tool-usage
def interact_with_agent(prompt, messages=[]):
"""Simulate generation of two assistant messages after delays"""
time.sleep(2)
messages.append(
gr.ChatMessage(
role="assistant", content="Progress timer stops here (or becomes invisible)"
)
)
yield messages
time.sleep(2)
messages.append(
gr.ChatMessage(role="assistant", content="But I want it to stop here")
)
yield messages
def str_to_message(content, role="user"):
return [gr.ChatMessage(role=role, content=content)]
with gr.Blocks() as demo:
chatbot = gr.Chatbot(
type="messages",
)
input = gr.Textbox(
"Start the simulation with two assistant messages after 2-second delays",
autofocus=True,
)
input.submit(
# Update chatbot UI with user message immediately
str_to_message,
input,
chatbot,
).then(
# Update chatbot UI with assistant messages
interact_with_agent,
[input, chatbot],
chatbot,
)
gr.Markdown(
"Reported as [Gradio issue #11637](https://github.com/gradio-app/gradio/issues/11637)"
)
demo.launch()