David Chu
commited on
Handle chat clear
Browse files
app.py
CHANGED
@@ -142,7 +142,7 @@ with gr.Blocks(title="🦎 Salamandra & Oranguten") as demo:
|
|
142 |
|
143 |
with gr.Column(scale=3):
|
144 |
chatbot = gr.Chatbot(height=450, type="messages")
|
145 |
-
|
146 |
placeholder="Type your message here...",
|
147 |
label="Your message",
|
148 |
submit_btn=True,
|
@@ -154,22 +154,25 @@ with gr.Blocks(title="🦎 Salamandra & Oranguten") as demo:
|
|
154 |
|
155 |
response_safety = gr.Label(show_label=False)
|
156 |
|
157 |
-
|
|
|
158 |
assistant,
|
159 |
inputs=[chatbot, system_prompt, model_selector],
|
160 |
outputs=[chatbot, response_safety],
|
161 |
)
|
162 |
|
163 |
-
model_selector.change(lambda: [], outputs=chatbot)
|
164 |
system_prompt_selector.change(
|
165 |
lambda example_name: EXAMPLE_PROMPTS[example_name],
|
166 |
inputs=system_prompt_selector,
|
167 |
outputs=system_prompt,
|
168 |
)
|
169 |
-
system_prompt.change(lambda: [], outputs=chatbot)
|
170 |
|
171 |
-
|
172 |
-
|
|
|
|
|
|
|
|
|
173 |
outputs=[
|
174 |
chatbot,
|
175 |
system_prompt,
|
@@ -179,5 +182,17 @@ with gr.Blocks(title="🦎 Salamandra & Oranguten") as demo:
|
|
179 |
],
|
180 |
queue=False,
|
181 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
182 |
|
183 |
demo.launch()
|
|
|
142 |
|
143 |
with gr.Column(scale=3):
|
144 |
chatbot = gr.Chatbot(height=450, type="messages")
|
145 |
+
message = gr.Textbox(
|
146 |
placeholder="Type your message here...",
|
147 |
label="Your message",
|
148 |
submit_btn=True,
|
|
|
154 |
|
155 |
response_safety = gr.Label(show_label=False)
|
156 |
|
157 |
+
# Event Listeners:
|
158 |
+
message.submit(user, inputs=[message, chatbot], outputs=[message, chatbot]).then(
|
159 |
assistant,
|
160 |
inputs=[chatbot, system_prompt, model_selector],
|
161 |
outputs=[chatbot, response_safety],
|
162 |
)
|
163 |
|
|
|
164 |
system_prompt_selector.change(
|
165 |
lambda example_name: EXAMPLE_PROMPTS[example_name],
|
166 |
inputs=system_prompt_selector,
|
167 |
outputs=system_prompt,
|
168 |
)
|
|
|
169 |
|
170 |
+
@model_selector.change(outputs=chatbot)
|
171 |
+
@system_prompt.change(outputs=chatbot)
|
172 |
+
def clear_chat():
|
173 |
+
return []
|
174 |
+
|
175 |
+
@new_chat.click(
|
176 |
outputs=[
|
177 |
chatbot,
|
178 |
system_prompt,
|
|
|
182 |
],
|
183 |
queue=False,
|
184 |
)
|
185 |
+
@chatbot.clear(
|
186 |
+
outputs=[
|
187 |
+
chatbot,
|
188 |
+
system_prompt,
|
189 |
+
system_prompt_selector,
|
190 |
+
model_selector,
|
191 |
+
response_safety,
|
192 |
+
]
|
193 |
+
)
|
194 |
+
def reset():
|
195 |
+
return [], EXAMPLE_PROMPTS["Default"], "Default", "Salamandra", {}
|
196 |
+
|
197 |
|
198 |
demo.launch()
|