melk2025 commited on
Commit
e008b5f
·
verified ·
1 Parent(s): e2cb4e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -16
app.py CHANGED
@@ -252,30 +252,29 @@ def save_chat_to_file(chat_history):
252
 
253
  return file_path
254
 
255
- #def ask(user_message, chat_history):
256
- # if not user_message:
257
- # return chat_history, chat_history, ""
258
 
259
- # response = chatbot(user_message, chat_history)
260
- # chat_history.append((user_message, response))
 
261
 
262
- # return chat_history, chat_history, ""
263
-
264
- # Initialize chat history with a welcome message
265
- initial_message = (None, "Hello, how can I help you with Moodle?")
266
 
267
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
268
  chat_history = gr.State([initial_message])
269
 
270
- chatbot_ui = gr.Chatbot(value=[initial_message])
271
  question = gr.Textbox(placeholder="Ask me anything about Moodle...", show_label=False)
272
  clear_button = gr.Button("Clear")
273
  save_button = gr.Button("Save Chat")
274
 
275
- question.submit(ask, [question, chat_history], [chatbot_ui, chat_history, question])
276
- clear_button.click(lambda: ([initial_message], [initial_message], ""), None, [chatbot_ui, chat_history, question], queue=False)
277
-
 
 
 
 
278
  save_button.click(save_chat_to_file, [chat_history], gr.File(label="Download your chat history"))
279
-
280
- demo.queue()
281
- demo.launch(share=False)
 
252
 
253
  return file_path
254
 
255
+ def ask(user_message, chat_history):
256
+ if not user_message:
257
+ return chat_history
258
 
259
+ response = chatbot(user_message, chat_history)
260
+ chat_history.append((user_message, response))
261
+ return chat_history
262
 
263
+ # Initialize chat history with a welcome messageinitial_message = (None, "Hello, how can I help you with Moodle?")
 
 
 
264
 
265
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
266
  chat_history = gr.State([initial_message])
267
 
268
+ chatbot_ui = gr.Chatbot()
269
  question = gr.Textbox(placeholder="Ask me anything about Moodle...", show_label=False)
270
  clear_button = gr.Button("Clear")
271
  save_button = gr.Button("Save Chat")
272
 
273
+ question.submit(ask, [question, chat_history], [chatbot_ui, chat_history])
274
+ clear_button.click(
275
+ lambda: ([initial_message], [initial_message], ""),
276
+ None,
277
+ [chatbot_ui, chat_history, question],
278
+ queue=False
279
+ )
280
  save_button.click(save_chat_to_file, [chat_history], gr.File(label="Download your chat history"))