Nihal2000 commited on
Commit
dd4a6b9
·
verified ·
1 Parent(s): ae7cb8d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py CHANGED
@@ -457,6 +457,22 @@ def generate_tags_for_document(doc_choice, custom_text, max_tags):
457
  logger.error(f"Tag generation error: {str(e)}")
458
  return f"❌ Error: {str(e)}"
459
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
460
  def ask_question(question):
461
  """Gradio interface for Q&A"""
462
  if not question.strip():
@@ -519,6 +535,19 @@ def create_gradio_interface():
519
  fn=get_document_list,
520
  outputs=[document_list]
521
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
522
 
523
  # Document Ingestion Tab
524
  with gr.Tab("📄 Upload Documents"):
 
457
  logger.error(f"Tag generation error: {str(e)}")
458
  return f"❌ Error: {str(e)}"
459
 
460
+ def delete_document_from_library(document_id):
461
+ """deleting a document from the library"""
462
+ try:
463
+ # Run the async delete_document method
464
+ result = mcp_server.run_async(mcp_server.document_store.delete_document(document_id))
465
+ if result:
466
+ msg = f"🗑️ Document {document_id[:8]}... deleted successfully."
467
+ else:
468
+ msg = f"❌ Failed to delete document {document_id[:8]}..."
469
+ # Refresh document list and choices
470
+ doc_list = get_document_list()
471
+ doc_choices = get_document_choices()
472
+ return msg, doc_list, gr.update(choices=doc_choices)
473
+ except Exception as e:
474
+ return f"❌ Error: {str(e)}", get_document_list(), gr.update(choices=get_document_choices())
475
+
476
  def ask_question(question):
477
  """Gradio interface for Q&A"""
478
  if not question.strip():
 
535
  fn=get_document_list,
536
  outputs=[document_list]
537
  )
538
+ delete_doc_dropdown = gr.Dropdown(
539
+ label="Select Document to Delete",
540
+ choices=get_document_choices(),
541
+ value=None,
542
+ interactive=True,
543
+ allow_custom_value=False
544
+ )
545
+ delete_btn = gr.Button("🗑️ Delete Selected Document", variant="stop")
546
+ delete_btn.click(
547
+ delete_document_from_library,
548
+ inputs=[delete_doc_dropdown],
549
+ outputs=[document_list, document_list, delete_doc_dropdown]
550
+ )
551
 
552
  # Document Ingestion Tab
553
  with gr.Tab("📄 Upload Documents"):