CoolFace
Apppublic

abidlabs/chatbot_nested_thoughts2

sourceHugging Faceupdated 2y agoView on Hugging Face
0likes
run.py88 linesDownload Raw Back to root
1import gradio as gr2from gradio import ChatMessage3import time4 5sleep_time = 0.16long_sleep_time = 17 8def 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 history15    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 history23    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 history32    time.sleep(long_sleep_time)33    history[-1].content = "Will check: weather.com and sunny.org"34    yield history35    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 history44    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 history53    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 history63 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 history73    history.append(74        ChatMessage(75            role="assistant",76            content="Failed again",77            metadata={"title": "Failed again", "id": 7, "parent_id": 1},78        )79    )80    yield history81 82with gr.Blocks() as demo:83    chatbot = gr.Chatbot(type="messages", height=500, show_copy_button=True)84    demo.load(generate_response, chatbot, chatbot)85 86if __name__ == "__main__":87    demo.launch()88