serverdaun commited on
Commit
7024dee
·
1 Parent(s): 2f81d82

Add reset index functionality: implement reset_index function to drop the collection in Milvus and add UI elements for resetting the index in the app interface.

Browse files
Files changed (1) hide show
  1. app.py +17 -0
app.py CHANGED
@@ -69,6 +69,16 @@ def reset_collection_if_no_docs():
69
  print(f"Error resetting collection on startup: {e}")
70
 
71
 
 
 
 
 
 
 
 
 
 
 
72
  def index_documents(file_list):
73
  """Index documents from a list of files."""
74
  if not file_list:
@@ -125,6 +135,9 @@ with gr.Blocks() as demo:
125
  index_button = gr.Button("Update Index")
126
  index_status = gr.Textbox(label="Indexing Status")
127
 
 
 
 
128
  with gr.Tab("Chat"):
129
  gr.ChatInterface(chat_interface)
130
 
@@ -133,6 +146,10 @@ with gr.Blocks() as demo:
133
  inputs=[file_input],
134
  outputs=[index_status],
135
  )
 
 
 
 
136
 
137
  if __name__ == "__main__":
138
  # Ensure the documents directory exists from the start
 
69
  print(f"Error resetting collection on startup: {e}")
70
 
71
 
72
+ def reset_index():
73
+ """Reset the index."""
74
+ try:
75
+ if milvus_client and milvus_client.has_collection(COLLECTION_NAME):
76
+ milvus_client.drop_collection(COLLECTION_NAME)
77
+ print(f"Dropped collection {COLLECTION_NAME}.")
78
+ except Exception as e:
79
+ print(f"Error dropping collection during cleanup: {e}")
80
+
81
+
82
  def index_documents(file_list):
83
  """Index documents from a list of files."""
84
  if not file_list:
 
135
  index_button = gr.Button("Update Index")
136
  index_status = gr.Textbox(label="Indexing Status")
137
 
138
+ reset_index_button = gr.Button("Reset Index")
139
+ reset_index_status = gr.Textbox(label="Resetting Index Status")
140
+
141
  with gr.Tab("Chat"):
142
  gr.ChatInterface(chat_interface)
143
 
 
146
  inputs=[file_input],
147
  outputs=[index_status],
148
  )
149
+ reset_index_button.click(
150
+ fn=reset_index,
151
+ inputs=[]
152
+ )
153
 
154
  if __name__ == "__main__":
155
  # Ensure the documents directory exists from the start