Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
|
@@ -13,13 +13,12 @@ co = cohere.Client(cohere_api_key)
|
|
| 13 |
|
| 14 |
history = []
|
| 15 |
chat = []
|
| 16 |
-
cid = str(uuid.uuid4())
|
| 17 |
|
| 18 |
def trigger_example(example):
|
| 19 |
chat, updated_history = generate_response(example)
|
| 20 |
return chat, updated_history
|
| 21 |
|
| 22 |
-
def generate_response(user_message, history=None):
|
| 23 |
|
| 24 |
if history is None:
|
| 25 |
history = []
|
|
@@ -41,14 +40,14 @@ def generate_response(user_message, history=None):
|
|
| 41 |
(history[i].strip(), history[i + 1].strip())
|
| 42 |
for i in range(0, len(history) - 1, 2)
|
| 43 |
]
|
| 44 |
-
yield chat, history
|
| 45 |
|
| 46 |
-
return chat, history
|
| 47 |
|
| 48 |
|
| 49 |
-
def clear_chat():
|
| 50 |
-
cid = str(uuid.uuid4())
|
| 51 |
-
return [], []
|
| 52 |
|
| 53 |
|
| 54 |
examples = [
|
|
@@ -75,7 +74,8 @@ custom_css = """
|
|
| 75 |
"""
|
| 76 |
|
| 77 |
with gr.Blocks(analytics_enabled=False, css=custom_css) as demo:
|
| 78 |
-
|
|
|
|
| 79 |
with gr.Row():
|
| 80 |
with gr.Column(scale=1):
|
| 81 |
gr.Image("logoplus.png", elem_id="logo-img", show_label=False, show_share_button=False, show_download_button=False)
|
|
@@ -104,14 +104,16 @@ with gr.Blocks(analytics_enabled=False, css=custom_css) as demo:
|
|
| 104 |
|
| 105 |
|
| 106 |
history = gr.State([])
|
| 107 |
-
cid = str(uuid.uuid4())
|
| 108 |
-
|
| 109 |
|
| 110 |
-
user_message.submit(fn=generate_response, inputs=[user_message, history], outputs=[chatbot, history], concurrency_limit=32)
|
| 111 |
|
| 112 |
-
submit_button.click(fn=generate_response, inputs=[user_message, history], outputs=[chatbot, history], concurrency_limit=32)
|
| 113 |
-
clear_button.click(fn=clear_chat, inputs=
|
| 114 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
with gr.Row():
|
| 116 |
gr.Examples(
|
| 117 |
examples=examples,
|
|
|
|
| 13 |
|
| 14 |
history = []
|
| 15 |
chat = []
|
|
|
|
| 16 |
|
| 17 |
def trigger_example(example):
|
| 18 |
chat, updated_history = generate_response(example)
|
| 19 |
return chat, updated_history
|
| 20 |
|
| 21 |
+
def generate_response(user_message, cid, history=None):
|
| 22 |
|
| 23 |
if history is None:
|
| 24 |
history = []
|
|
|
|
| 40 |
(history[i].strip(), history[i + 1].strip())
|
| 41 |
for i in range(0, len(history) - 1, 2)
|
| 42 |
]
|
| 43 |
+
yield chat, history, cid
|
| 44 |
|
| 45 |
+
return chat, history, cid
|
| 46 |
|
| 47 |
|
| 48 |
+
def clear_chat(cid):
|
| 49 |
+
cid = gr.State(str(uuid.uuid4()))
|
| 50 |
+
return [], [], cid
|
| 51 |
|
| 52 |
|
| 53 |
examples = [
|
|
|
|
| 74 |
"""
|
| 75 |
|
| 76 |
with gr.Blocks(analytics_enabled=False, css=custom_css) as demo:
|
| 77 |
+
cid = gr.State(str(uuid.uuid4()))
|
| 78 |
+
|
| 79 |
with gr.Row():
|
| 80 |
with gr.Column(scale=1):
|
| 81 |
gr.Image("logoplus.png", elem_id="logo-img", show_label=False, show_share_button=False, show_download_button=False)
|
|
|
|
| 104 |
|
| 105 |
|
| 106 |
history = gr.State([])
|
|
|
|
|
|
|
| 107 |
|
| 108 |
+
user_message.submit(fn=generate_response, inputs=[user_message, cid, history], outputs=[chatbot, history, cid], concurrency_limit=32)
|
| 109 |
|
| 110 |
+
submit_button.click(fn=generate_response, inputs=[user_message, cid, history], outputs=[chatbot, history, cid], concurrency_limit=32)
|
| 111 |
+
clear_button.click(fn=clear_chat, inputs=[cid], outputs=[chatbot, history, cid], concurrency_limit=32)
|
| 112 |
|
| 113 |
+
user_message.submit(lambda x: gr.update(value=""), None, [user_message], queue=False)
|
| 114 |
+
submit_button.click(lambda x: gr.update(value=""), None, [user_message], queue=False)
|
| 115 |
+
clear_button.click(lambda x: gr.update(value=""), None, [user_message], queue=False)
|
| 116 |
+
|
| 117 |
with gr.Row():
|
| 118 |
gr.Examples(
|
| 119 |
examples=examples,
|