shukdevdattaEX commited on
Commit
c084196
·
verified ·
1 Parent(s): cd0b2cf

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -11
app.py CHANGED
@@ -193,7 +193,7 @@ def view_selected_conversation(selection):
193
  # Function to delete selected conversation
194
  def delete_selected_conversation(selection):
195
  if not selection or selection == "Select a conversation":
196
- return "Please select a conversation to delete.", gr.update()
197
 
198
  try:
199
  # Extract conversation number from selection
@@ -215,13 +215,17 @@ def delete_selected_conversation(selection):
215
 
216
  # Update dropdown choices
217
  choices = get_conversation_choices()
218
- return f"Conversation {conv_number + 1} deleted successfully!", gr.update(choices=choices, value="Select a conversation")
 
 
 
 
219
  else:
220
- return "Conversation not found.", gr.update()
221
 
222
- return "No conversations file found.", gr.update()
223
  except Exception as e:
224
- return f"Error deleting conversation: {str(e)}", gr.update()
225
 
226
  # Function to clear current conversation
227
  def clear_conversation():
@@ -234,10 +238,10 @@ def delete_all_conversations():
234
  try:
235
  if os.path.exists("conversations.json"):
236
  os.remove("conversations.json")
237
- return "All conversations deleted successfully!", gr.update(choices=[], value="Select a conversation")
238
- return "No conversations to delete.", gr.update()
239
  except Exception as e:
240
- return f"Error deleting conversations: {str(e)}", gr.update()
241
 
242
  # Function to refresh dropdown
243
  def refresh_dropdown():
@@ -276,7 +280,8 @@ with gr.Blocks(title="Chat with Documents 💬 📚") as demo:
276
  with gr.Column(scale=3):
277
  chatbot = gr.Chatbot(
278
  label="Chat",
279
- height=400
 
280
  )
281
  msg = gr.Textbox(
282
  label="Your Question",
@@ -374,12 +379,12 @@ with gr.Blocks(title="Chat with Documents 💬 📚") as demo:
374
  delete_selected_btn.click(
375
  fn=delete_selected_conversation,
376
  inputs=conversation_dropdown,
377
- outputs=[delete_status, conversation_dropdown]
378
  )
379
 
380
  delete_all_btn.click(
381
  fn=delete_all_conversations,
382
- outputs=[delete_status, conversation_dropdown]
383
  )
384
 
385
  if __name__ == "__main__":
 
193
  # Function to delete selected conversation
194
  def delete_selected_conversation(selection):
195
  if not selection or selection == "Select a conversation":
196
+ return "Please select a conversation to delete.", gr.update(), ""
197
 
198
  try:
199
  # Extract conversation number from selection
 
215
 
216
  # Update dropdown choices
217
  choices = get_conversation_choices()
218
+
219
+ # Get updated all conversations display
220
+ all_convs = load_conversations()
221
+
222
+ return f"Conversation {conv_number + 1} deleted successfully!", gr.update(choices=choices, value="Select a conversation"), all_convs
223
  else:
224
+ return "Conversation not found.", gr.update(), ""
225
 
226
+ return "No conversations file found.", gr.update(), ""
227
  except Exception as e:
228
+ return f"Error deleting conversation: {str(e)}", gr.update(), ""
229
 
230
  # Function to clear current conversation
231
  def clear_conversation():
 
238
  try:
239
  if os.path.exists("conversations.json"):
240
  os.remove("conversations.json")
241
+ return "All conversations deleted successfully!", gr.update(choices=[], value="Select a conversation"), "No previous conversations found."
242
+ return "No conversations to delete.", gr.update(), "No previous conversations found."
243
  except Exception as e:
244
+ return f"Error deleting conversations: {str(e)}", gr.update(), ""
245
 
246
  # Function to refresh dropdown
247
  def refresh_dropdown():
 
280
  with gr.Column(scale=3):
281
  chatbot = gr.Chatbot(
282
  label="Chat",
283
+ height=400,
284
+ type="messages"
285
  )
286
  msg = gr.Textbox(
287
  label="Your Question",
 
379
  delete_selected_btn.click(
380
  fn=delete_selected_conversation,
381
  inputs=conversation_dropdown,
382
+ outputs=[delete_status, conversation_dropdown, convs_display]
383
  )
384
 
385
  delete_all_btn.click(
386
  fn=delete_all_conversations,
387
+ outputs=[delete_status, conversation_dropdown, convs_display]
388
  )
389
 
390
  if __name__ == "__main__":