Fixed issue with clear button
Browse files
app.py
CHANGED
|
@@ -184,9 +184,9 @@ def respond(message, chat_history, temperature=0.9, top_p=0.6, max_token_count=5
|
|
| 184 |
|
| 185 |
stream, prompt_and_time, suggestions = get_answer(message, formatted_history, temperature, top_p, max_token_count)
|
| 186 |
|
| 187 |
-
|
| 188 |
-
|
| 189 |
-
|
| 190 |
|
| 191 |
for idx, text_token in enumerate(stream):
|
| 192 |
if idx == 0 and text_token.startswith(" "):
|
|
@@ -195,13 +195,11 @@ def respond(message, chat_history, temperature=0.9, top_p=0.6, max_token_count=5
|
|
| 195 |
chat_history[-1][1] += text_token
|
| 196 |
yield (
|
| 197 |
"", chat_history, prompt_and_time,
|
| 198 |
-
|
| 199 |
-
suggestions[1], suggestion2_visible,
|
| 200 |
-
suggestions[2], suggestion3_visible
|
| 201 |
)
|
| 202 |
|
| 203 |
def clear_chat_history():
|
| 204 |
-
return '', []
|
| 205 |
|
| 206 |
def main():
|
| 207 |
with gr.Blocks(css="""
|
|
@@ -210,15 +208,11 @@ def main():
|
|
| 210 |
}
|
| 211 |
""") as demo:
|
| 212 |
chatbot = gr.Chatbot([[None, initial_message]], height=600)
|
| 213 |
-
|
| 214 |
-
suggestion1_visible = gr.State(value=True)
|
| 215 |
-
suggestion2_visible = gr.State(value=True)
|
| 216 |
-
suggestion3_visible = gr.State(value=True)
|
| 217 |
|
| 218 |
with gr.Row():
|
| 219 |
-
suggestion1 = gr.Button("How to edit RFID crew badge?", elem_classes="suggestion-button", visible=
|
| 220 |
-
suggestion2 = gr.Button("What types of RFID tags exist?", elem_classes="suggestion-button", visible=
|
| 221 |
-
suggestion3 = gr.Button("Is it possible to delete a facility?", elem_classes="suggestion-button", visible=
|
| 222 |
|
| 223 |
msg = gr.Textbox(label="Question")
|
| 224 |
|
|
@@ -236,9 +230,7 @@ def main():
|
|
| 236 |
]
|
| 237 |
outputs = [
|
| 238 |
msg, chatbot, prompt_and_time,
|
| 239 |
-
suggestion1,
|
| 240 |
-
suggestion2, suggestion2_visible,
|
| 241 |
-
suggestion3, suggestion3_visible
|
| 242 |
]
|
| 243 |
|
| 244 |
btn.click(respond, inputs=inputs, outputs=outputs)
|
|
@@ -261,7 +253,10 @@ def main():
|
|
| 261 |
|
| 262 |
msg.submit(respond, inputs=inputs, outputs=outputs)
|
| 263 |
|
| 264 |
-
clear.click(clear_chat_history, outputs=[
|
|
|
|
|
|
|
|
|
|
| 265 |
|
| 266 |
demo.queue().launch()
|
| 267 |
|
|
|
|
| 184 |
|
| 185 |
stream, prompt_and_time, suggestions = get_answer(message, formatted_history, temperature, top_p, max_token_count)
|
| 186 |
|
| 187 |
+
suggestion1_update = gr.update(visible=bool(suggestions[0]), value=suggestions[0])
|
| 188 |
+
suggestion2_update = gr.update(visible=bool(suggestions[1]), value=suggestions[1])
|
| 189 |
+
suggestion3_update = gr.update(visible=bool(suggestions[2]), value=suggestions[2])
|
| 190 |
|
| 191 |
for idx, text_token in enumerate(stream):
|
| 192 |
if idx == 0 and text_token.startswith(" "):
|
|
|
|
| 195 |
chat_history[-1][1] += text_token
|
| 196 |
yield (
|
| 197 |
"", chat_history, prompt_and_time,
|
| 198 |
+
suggestion1_update, suggestion2_update, suggestion3_update
|
|
|
|
|
|
|
| 199 |
)
|
| 200 |
|
| 201 |
def clear_chat_history():
|
| 202 |
+
return '', [], '', gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
| 203 |
|
| 204 |
def main():
|
| 205 |
with gr.Blocks(css="""
|
|
|
|
| 208 |
}
|
| 209 |
""") as demo:
|
| 210 |
chatbot = gr.Chatbot([[None, initial_message]], height=600)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
|
| 212 |
with gr.Row():
|
| 213 |
+
suggestion1 = gr.Button("How to edit RFID crew badge?", elem_classes="suggestion-button", visible=True)
|
| 214 |
+
suggestion2 = gr.Button("What types of RFID tags exist?", elem_classes="suggestion-button", visible=True)
|
| 215 |
+
suggestion3 = gr.Button("Is it possible to delete a facility?", elem_classes="suggestion-button", visible=True)
|
| 216 |
|
| 217 |
msg = gr.Textbox(label="Question")
|
| 218 |
|
|
|
|
| 230 |
]
|
| 231 |
outputs = [
|
| 232 |
msg, chatbot, prompt_and_time,
|
| 233 |
+
suggestion1, suggestion2, suggestion3
|
|
|
|
|
|
|
| 234 |
]
|
| 235 |
|
| 236 |
btn.click(respond, inputs=inputs, outputs=outputs)
|
|
|
|
| 253 |
|
| 254 |
msg.submit(respond, inputs=inputs, outputs=outputs)
|
| 255 |
|
| 256 |
+
clear.click(clear_chat_history, outputs=[
|
| 257 |
+
msg, chatbot, prompt_and_time,
|
| 258 |
+
suggestion1, suggestion2, suggestion3
|
| 259 |
+
])
|
| 260 |
|
| 261 |
demo.queue().launch()
|
| 262 |
|