Spaces:
Runtime error
Runtime error
MarziehFadaee
commited on
fix conversation id leakage
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,25 +40,26 @@ 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 |
-
|
51 |
-
return [], []
|
52 |
|
53 |
|
54 |
examples = [
|
55 |
-
"What are
|
56 |
-
"Create a list of unusual excuses people might use to get out of a work meeting",
|
57 |
-
"Write a python code to reverse a string",
|
58 |
-
"Explain the relativity theory in French",
|
59 |
-
"Como sair de um helicóptero que caiu na água?",
|
60 |
-
"Formally introduce the transformer architecture with notation.",
|
61 |
-
"¿Cómo le explicarías el aprendizaje automático a un extraterrestre?",
|
62 |
-
"Summarize recent news about the North American tech job market"
|
|
|
|
|
63 |
]
|
64 |
|
65 |
title = """<h1 align="center">Cohere for AI Command R</h1>"""
|
@@ -75,7 +75,8 @@ custom_css = """
|
|
75 |
|
76 |
with gr.Blocks(analytics_enabled=False, css=custom_css) as demo:
|
77 |
#gr.HTML(title)
|
78 |
-
|
|
|
79 |
with gr.Row():
|
80 |
with gr.Column(scale=1):
|
81 |
gr.Image("logo2.png", elem_id="logo-img", show_label=False, show_share_button=False, show_download_button=False)
|
@@ -101,17 +102,18 @@ with gr.Blocks(analytics_enabled=False, css=custom_css) as demo:
|
|
101 |
with gr.Row():
|
102 |
submit_button = gr.Button("Submit")
|
103 |
clear_button = gr.Button("Clear chat")
|
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 |
-
|
113 |
-
clear_button.click(fn=clear_chat, inputs=None, outputs=[chatbot, history], concurrency_limit=32)
|
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():
|
49 |
+
return [], [], str(uuid.uuid4())
|
|
|
50 |
|
51 |
|
52 |
examples = [
|
53 |
+
"What are 8 good questions to get to know a stranger?",
|
54 |
+
"Create a list of 10 unusual excuses people might use to get out of a work meeting",
|
55 |
+
"Write a python code to reverse a string",
|
56 |
+
"Explain the relativity theory in French",
|
57 |
+
"Como sair de um helicóptero que caiu na água?",
|
58 |
+
"Formally introduce the transformer architecture with notation.",
|
59 |
+
"¿Cómo le explicarías el aprendizaje automático a un extraterrestre?",
|
60 |
+
"Summarize recent news about the North American tech job market",
|
61 |
+
"My coworker brought some delicious treats from their recent trip to the office to share. Would it be immoral if I took most of not all of these treats?",
|
62 |
+
"Explain gravity to a chicken."
|
63 |
]
|
64 |
|
65 |
title = """<h1 align="center">Cohere for AI Command R</h1>"""
|
|
|
75 |
|
76 |
with gr.Blocks(analytics_enabled=False, css=custom_css) as demo:
|
77 |
#gr.HTML(title)
|
78 |
+
cid = gr.State(str(uuid.uuid4()))
|
79 |
+
|
80 |
with gr.Row():
|
81 |
with gr.Column(scale=1):
|
82 |
gr.Image("logo2.png", elem_id="logo-img", show_label=False, show_share_button=False, show_download_button=False)
|
|
|
102 |
with gr.Row():
|
103 |
submit_button = gr.Button("Submit")
|
104 |
clear_button = gr.Button("Clear chat")
|
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 |
+
submit_button.click(fn=generate_response, inputs=[user_message, cid, history], outputs=[chatbot, history, cid], concurrency_limit=32)
|
110 |
+
clear_button.click(fn=clear_chat, inputs=None, outputs=[chatbot, history, cid], concurrency_limit=32)
|
|
|
111 |
|
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,
|