adf0d17497
publish / version_or_publish (push) Has been cancelled
storybook-build / changes (push) Has been cancelled
storybook-build / :storybook-build (push) Has been cancelled
Sync Gradio Skills to Hugging Face / sync-skills (push) Has been cancelled
functional / changes (push) Has been cancelled
functional / build-frontend (push) Has been cancelled
functional / functional-test-SSR=false (push) Has been cancelled
functional / functional-reload (push) Has been cancelled
js / changes (push) Has been cancelled
js / js-test (push) Has been cancelled
docs-build / changes (push) Has been cancelled
docs-build / docs-build (push) Has been cancelled
docs-build / website-build (push) Has been cancelled
functional / functional-test-SSR=true (push) Has been cancelled
hygiene / hygiene-test (push) Has been cancelled
python / changes (push) Has been cancelled
python / build (push) Has been cancelled
python / test-ubuntu-latest-flaky (push) Has been cancelled
python / test-ubuntu-latest-not-flaky (push) Has been cancelled
python / test-windows-latest-flaky (push) Has been cancelled
python / test-windows-latest-not-flaky (push) Has been cancelled
49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
import gradio as gr
|
|
from gradio import ChatMessage
|
|
import time
|
|
|
|
sleep_time = 0.5
|
|
|
|
def simulate_thinking_chat(message, history):
|
|
start_time = time.time()
|
|
response = ChatMessage(
|
|
content="",
|
|
metadata={"title": "_Thinking_ step-by-step", "id": 0, "status": "pending"}
|
|
)
|
|
yield response
|
|
|
|
thoughts = [
|
|
"First, I need to understand the core aspects of the query...",
|
|
"Now, considering the broader context and implications...",
|
|
"Analyzing potential approaches to formulate a comprehensive answer...",
|
|
"Finally, structuring the response for clarity and completeness..."
|
|
]
|
|
|
|
accumulated_thoughts = ""
|
|
for thought in thoughts:
|
|
time.sleep(sleep_time)
|
|
accumulated_thoughts += f"- {thought}\n\n"
|
|
response.content = accumulated_thoughts.strip()
|
|
yield response
|
|
|
|
response.metadata["status"] = "done"
|
|
response.metadata["duration"] = time.time() - start_time
|
|
yield response
|
|
|
|
response = [
|
|
response,
|
|
ChatMessage(
|
|
content="Based on my thoughts and analysis above, my response is: This dummy repro shows how thoughts of a thinking LLM can be progressively shown before providing its final answer."
|
|
)
|
|
]
|
|
yield response
|
|
|
|
|
|
demo = gr.ChatInterface(
|
|
simulate_thinking_chat,
|
|
title="Thinking LLM Chat Interface 🤔",
|
|
)
|
|
|
|
if __name__ == "__main__":
|
|
demo.launch()
|