freddyaboulton HF Staff commited on
Commit
ccdc491
·
verified ·
1 Parent(s): e2f02dd

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +1 -1
  2. run.ipynb +1 -1
  3. run.py +1 -1
README.md CHANGED
@@ -5,7 +5,7 @@ emoji: 🔥
5
  colorFrom: indigo
6
  colorTo: indigo
7
  sdk: gradio
8
- sdk_version: 5.49.1
9
  app_file: run.py
10
  pinned: false
11
  hf_oauth: true
 
5
  colorFrom: indigo
6
  colorTo: indigo
7
  sdk: gradio
8
+ sdk_version: 6.0.0
9
  app_file: run.py
10
  pinned: false
11
  hf_oauth: true
run.ipynb CHANGED
@@ -1 +1 @@
1
- {"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: chatbot_thoughts"]}, {"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 simulate_thinking_chat(message: str, history: list):\n", " history.append(\n", " ChatMessage(\n", " role=\"assistant\",\n", " content=\"\",\n", " metadata={\"title\": \"Thinking... \", \"log\": \"Starting analysis\"}\n", " )\n", " )\n", " time.sleep(0.5)\n", " yield history\n", "\n", " thoughts = [\n", " \"First, I need to understand the core aspects of the query...\",\n", " \"Now, considering the broader context and implications...\",\n", " \"Analyzing potential approaches to formulate a comprehensive answer...\",\n", " \"Finally, structuring the response for clarity and completeness...\"\n", " ]\n", "\n", " accumulated_thoughts = \"\"\n", "\n", " for i, thought in enumerate(thoughts):\n", " time.sleep(0.5)\n", "\n", " accumulated_thoughts += f\"- {thought}\\n\\n\"\n", "\n", " history[-1] = ChatMessage(\n", " role=\"assistant\",\n", " content=accumulated_thoughts.strip(),\n", " metadata={\n", " \"title\": \"Thinking...\",\n", " \"log\": f\"Step {i+1} completed.\",\n", " \"duration\": 0.5 * (i + 1)\n", " }\n", " )\n", " yield history\n", "\n", " history.append(\n", " ChatMessage(\n", " role=\"assistant\",\n", " 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.\"\n", " )\n", " )\n", " yield history\n", "\n", "with gr.Blocks() as demo:\n", " gr.Markdown(\"# Thinking LLM Demo \ud83e\udd14\")\n", " chatbot = gr.Chatbot(type=\"messages\", render_markdown=True)\n", " msg = gr.Textbox(placeholder=\"Type your message...\")\n", "\n", " msg.submit(\n", " lambda m, h: (m, h + [ChatMessage(role=\"user\", content=m)]),\n", " [msg, chatbot],\n", " [msg, chatbot]\n", " ).then(\n", " simulate_thinking_chat,\n", " [msg, chatbot],\n", " chatbot\n", " )\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
 
1
+ {"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: chatbot_thoughts"]}, {"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 simulate_thinking_chat(message: str, history: list):\n", " history.append(\n", " ChatMessage(\n", " role=\"assistant\",\n", " content=\"\",\n", " metadata={\"title\": \"Thinking... \", \"log\": \"Starting analysis\"}\n", " )\n", " )\n", " time.sleep(0.5)\n", " yield history\n", "\n", " thoughts = [\n", " \"First, I need to understand the core aspects of the query...\",\n", " \"Now, considering the broader context and implications...\",\n", " \"Analyzing potential approaches to formulate a comprehensive answer...\",\n", " \"Finally, structuring the response for clarity and completeness...\"\n", " ]\n", "\n", " accumulated_thoughts = \"\"\n", "\n", " for i, thought in enumerate(thoughts):\n", " time.sleep(0.5)\n", "\n", " accumulated_thoughts += f\"- {thought}\\n\\n\"\n", "\n", " history[-1] = ChatMessage(\n", " role=\"assistant\",\n", " content=accumulated_thoughts.strip(),\n", " metadata={\n", " \"title\": \"Thinking...\",\n", " \"log\": f\"Step {i+1} completed.\",\n", " \"duration\": 0.5 * (i + 1)\n", " }\n", " )\n", " yield history\n", "\n", " history.append(\n", " ChatMessage(\n", " role=\"assistant\",\n", " 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.\"\n", " )\n", " )\n", " yield history\n", "\n", "with gr.Blocks() as demo:\n", " gr.Markdown(\"# Thinking LLM Demo \ud83e\udd14\")\n", " chatbot = gr.Chatbot(render_markdown=True)\n", " msg = gr.Textbox(placeholder=\"Type your message...\")\n", "\n", " msg.submit(\n", " lambda m, h: (m, h + [ChatMessage(role=\"user\", content=m)]),\n", " [msg, chatbot],\n", " [msg, chatbot]\n", " ).then(\n", " simulate_thinking_chat,\n", " [msg, chatbot],\n", " chatbot\n", " )\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
run.py CHANGED
@@ -48,7 +48,7 @@ def simulate_thinking_chat(message: str, history: list):
48
 
49
  with gr.Blocks() as demo:
50
  gr.Markdown("# Thinking LLM Demo 🤔")
51
- chatbot = gr.Chatbot(type="messages", render_markdown=True)
52
  msg = gr.Textbox(placeholder="Type your message...")
53
 
54
  msg.submit(
 
48
 
49
  with gr.Blocks() as demo:
50
  gr.Markdown("# Thinking LLM Demo 🤔")
51
+ chatbot = gr.Chatbot(render_markdown=True)
52
  msg = gr.Textbox(placeholder="Type your message...")
53
 
54
  msg.submit(