freddyaboulton HF staff commited on
Commit
db29f75
·
verified ·
1 Parent(s): 91c8508

Upload folder using huggingface_hub

Browse files
Files changed (3) hide show
  1. README.md +7 -7
  2. run.ipynb +1 -0
  3. run.py +79 -0
README.md CHANGED
@@ -1,12 +1,12 @@
 
1
  ---
2
- title: Chatbot Nested Thoughts
3
- emoji: 🌍
4
- colorFrom: gray
5
- colorTo: green
6
  sdk: gradio
7
  sdk_version: 5.11.0
8
- app_file: app.py
9
  pinned: false
 
10
  ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
+
2
  ---
3
+ title: chatbot_nested_thoughts
4
+ emoji: 🔥
5
+ colorFrom: indigo
6
+ colorTo: indigo
7
  sdk: gradio
8
  sdk_version: 5.11.0
9
+ app_file: run.py
10
  pinned: false
11
+ hf_oauth: true
12
  ---
 
 
run.ipynb ADDED
@@ -0,0 +1 @@
 
 
1
+ {"cells": [{"cell_type": "markdown", "id": "302934307671667531413257853548643485645", "metadata": {}, "source": ["# Gradio Demo: chatbot_nested_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", "sleep_time = 0.1\n", "long_sleep_time = 1\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(sleep_time)\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(sleep_time)\n", " history.append(\n", " ChatMessage(\n", " role=\"assistant\",\n", " content=\"\",\n", " metadata={\"title\": \"Gathering Weather Websites\", \"id\": 1},\n", " )\n", " )\n", " yield history\n", " time.sleep(long_sleep_time)\n", " history[-1].content = \"Will check: weather.com and sunny.org\"\n", " yield history\n", " time.sleep(sleep_time)\n", " history.append(\n", " ChatMessage(\n", " role=\"assistant\",\n", " content=\"Received weather from weather.com.\",\n", " metadata={\"title\": \"API Success \u2705\", \"parent_id\": 1, \"id\": 2},\n", " )\n", " )\n", " yield history\n", " time.sleep(sleep_time)\n", " history.append(\n", " ChatMessage(\n", " role=\"assistant\",\n", " content=\"API Error when connecting to sunny.org.\",\n", " metadata={\"title\": \"API Error \ud83d\udca5 \", \"parent_id\": 1, \"id\": 3},\n", " )\n", " )\n", " yield history\n", " time.sleep(sleep_time)\n", "\n", " history.append(\n", " ChatMessage(\n", " role=\"assistant\",\n", " content=\"I will try yet again\",\n", " metadata={\"title\": \"I will try again\", \"id\": 4, \"parent_id\": 3},\n", " )\n", " )\n", " yield history\n", "\n", " time.sleep(sleep_time)\n", " history.append(\n", " ChatMessage(\n", " role=\"assistant\",\n", " content=\"Failed again\",\n", " metadata={\"title\": \"Failed again\", \"id\": 6, \"parent_id\": 4},\n", " )\n", " )\n", " yield history\n", "\n", "with gr.Blocks() as demo:\n", " chatbot = gr.Chatbot(type=\"messages\", height=500, show_copy_button=True)\n", " demo.load(generate_response, chatbot, chatbot)\n", "\n", "if __name__ == \"__main__\":\n", " demo.launch()\n"]}], "metadata": {}, "nbformat": 4, "nbformat_minor": 5}
run.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from gradio import ChatMessage
3
+ import time
4
+
5
+ sleep_time = 0.1
6
+ long_sleep_time = 1
7
+
8
+ def generate_response(history):
9
+ history.append(
10
+ ChatMessage(
11
+ role="user", content="What is the weather in San Francisco right now?"
12
+ )
13
+ )
14
+ yield history
15
+ time.sleep(sleep_time)
16
+ history.append(
17
+ ChatMessage(
18
+ role="assistant",
19
+ content="In order to find the current weather in San Francisco, I will need to use my weather tool.",
20
+ )
21
+ )
22
+ yield history
23
+ time.sleep(sleep_time)
24
+ history.append(
25
+ ChatMessage(
26
+ role="assistant",
27
+ content="",
28
+ metadata={"title": "Gathering Weather Websites", "id": 1},
29
+ )
30
+ )
31
+ yield history
32
+ time.sleep(long_sleep_time)
33
+ history[-1].content = "Will check: weather.com and sunny.org"
34
+ yield history
35
+ time.sleep(sleep_time)
36
+ history.append(
37
+ ChatMessage(
38
+ role="assistant",
39
+ content="Received weather from weather.com.",
40
+ metadata={"title": "API Success ✅", "parent_id": 1, "id": 2},
41
+ )
42
+ )
43
+ yield history
44
+ time.sleep(sleep_time)
45
+ history.append(
46
+ ChatMessage(
47
+ role="assistant",
48
+ content="API Error when connecting to sunny.org.",
49
+ metadata={"title": "API Error 💥 ", "parent_id": 1, "id": 3},
50
+ )
51
+ )
52
+ yield history
53
+ time.sleep(sleep_time)
54
+
55
+ history.append(
56
+ ChatMessage(
57
+ role="assistant",
58
+ content="I will try yet again",
59
+ metadata={"title": "I will try again", "id": 4, "parent_id": 3},
60
+ )
61
+ )
62
+ yield history
63
+
64
+ time.sleep(sleep_time)
65
+ history.append(
66
+ ChatMessage(
67
+ role="assistant",
68
+ content="Failed again",
69
+ metadata={"title": "Failed again", "id": 6, "parent_id": 4},
70
+ )
71
+ )
72
+ yield history
73
+
74
+ with gr.Blocks() as demo:
75
+ chatbot = gr.Chatbot(type="messages", height=500, show_copy_button=True)
76
+ demo.load(generate_response, chatbot, chatbot)
77
+
78
+ if __name__ == "__main__":
79
+ demo.launch()