adding saving chat
Browse files
app.py
CHANGED
|
@@ -270,6 +270,19 @@ def chatbot(query):
|
|
| 270 |
#demo.launch(share=False)
|
| 271 |
# Initialize chat history with a welcome message
|
| 272 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 273 |
initial_message = (None, "Hello, how can I help you with Moodle?")
|
| 274 |
|
| 275 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
@@ -285,3 +298,4 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 285 |
save_button.click(save_chat_to_file, [chat_history], None) # to save the chat
|
| 286 |
|
| 287 |
|
|
|
|
|
|
| 270 |
#demo.launch(share=False)
|
| 271 |
# Initialize chat history with a welcome message
|
| 272 |
|
| 273 |
+
def ask(user_message, chat_history):
|
| 274 |
+
if not user_message:
|
| 275 |
+
return chat_history, chat_history, ""
|
| 276 |
+
|
| 277 |
+
response = chatbot(user_message)
|
| 278 |
+
chat_history.append((user_message, response))
|
| 279 |
+
|
| 280 |
+
# Save chat history to file
|
| 281 |
+
with open(HISTORY_FILE, "w", encoding="utf-8") as f:
|
| 282 |
+
json.dump(chat_history, f, ensure_ascii=False, indent=2)
|
| 283 |
+
|
| 284 |
+
return chat_history, chat_history, ""
|
| 285 |
+
|
| 286 |
initial_message = (None, "Hello, how can I help you with Moodle?")
|
| 287 |
|
| 288 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
|
|
| 298 |
save_button.click(save_chat_to_file, [chat_history], None) # to save the chat
|
| 299 |
|
| 300 |
|
| 301 |
+
|