Update app.py
Browse files
app.py
CHANGED
@@ -241,31 +241,47 @@ def chatbot(query):
|
|
241 |
# ---------------------- Gradio App ----------------------
|
242 |
|
243 |
# Define the chatbot response function
|
244 |
-
def ask(user_message, chat_history):
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
# Get chatbot response
|
249 |
-
|
250 |
|
251 |
# Update chat history
|
252 |
-
|
253 |
-
|
254 |
|
255 |
# Initialize chat history with a welcome message
|
256 |
-
initial_message = (None, "Hello, how can I help you with Moodle?")
|
257 |
|
258 |
# Build Gradio interface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
259 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
260 |
-
chat_history = gr.State([initial_message])
|
261 |
|
262 |
chatbot_ui = gr.Chatbot(value=[initial_message])
|
263 |
question = gr.Textbox(placeholder="Ask me anything about Moodle...", show_label=False)
|
264 |
clear_button = gr.Button("Clear")
|
|
|
265 |
|
266 |
question.submit(ask, [question, chat_history], [chatbot_ui, chat_history, question])
|
267 |
clear_button.click(lambda: ([initial_message], [initial_message], ""), None, [chatbot_ui, chat_history, question], queue=False)
|
|
|
268 |
|
269 |
-
demo.queue()
|
270 |
-
demo.launch(share=False)
|
271 |
|
|
|
241 |
# ---------------------- Gradio App ----------------------
|
242 |
|
243 |
# Define the chatbot response function
|
244 |
+
#def ask(user_message, chat_history):
|
245 |
+
# if not user_message:
|
246 |
+
# return chat_history, chat_history, ""
|
247 |
+
#
|
248 |
# Get chatbot response
|
249 |
+
# response = chatbot(user_message)
|
250 |
|
251 |
# Update chat history
|
252 |
+
# chat_history.append((user_message, response))
|
253 |
+
# return chat_history, chat_history, ""
|
254 |
|
255 |
# Initialize chat history with a welcome message
|
256 |
+
#initial_message = (None, "Hello, how can I help you with Moodle?")
|
257 |
|
258 |
# Build Gradio interface
|
259 |
+
#with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
260 |
+
#chat_history = gr.State([initial_message]) # <-- Move inside here!
|
261 |
+
|
262 |
+
# chatbot_ui = gr.Chatbot(value=[initial_message])
|
263 |
+
# question = gr.Textbox(placeholder="Ask me anything about Moodle...", show_label=False)
|
264 |
+
# clear_button = gr.Button("Clear")
|
265 |
+
|
266 |
+
# question.submit(ask, [question, chat_history], [chatbot_ui, chat_history, question])
|
267 |
+
# clear_button.click(lambda: ([initial_message], [initial_message], ""), None, [chatbot_ui, chat_history, question], queue=False)
|
268 |
+
|
269 |
+
#demo.queue()
|
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:
|
276 |
+
chat_history = gr.State([initial_message])
|
277 |
|
278 |
chatbot_ui = gr.Chatbot(value=[initial_message])
|
279 |
question = gr.Textbox(placeholder="Ask me anything about Moodle...", show_label=False)
|
280 |
clear_button = gr.Button("Clear")
|
281 |
+
save_button = gr.Button("Save Chat") # to save the chat
|
282 |
|
283 |
question.submit(ask, [question, chat_history], [chatbot_ui, chat_history, question])
|
284 |
clear_button.click(lambda: ([initial_message], [initial_message], ""), None, [chatbot_ui, chat_history, question], queue=False)
|
285 |
+
save_button.click(save_chat_to_file, [chat_history], None) # to save the chat
|
286 |
|
|
|
|
|
287 |
|