Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -75,21 +75,6 @@ def process_files(file_list, progress=gr.Progress()):
|
|
75 |
return f"Embedding process completed and database created. Processed {len(documents)} files. You can now start chatting!"
|
76 |
|
77 |
|
78 |
-
def load_existing_index(folder_path):
|
79 |
-
global vector_store
|
80 |
-
try:
|
81 |
-
index_file = os.path.join(folder_path, "index.faiss")
|
82 |
-
pkl_file = os.path.join(folder_path, "index.pkl")
|
83 |
-
|
84 |
-
if not os.path.exists(index_file) or not os.path.exists(pkl_file):
|
85 |
-
return f"Error: FAISS index files not found in {folder_path}. Please ensure both 'index.faiss' and 'index.pkl' are present."
|
86 |
-
|
87 |
-
vector_store = FAISS.load_local(folder_path, embeddings, allow_dangerous_deserialization=True)
|
88 |
-
return f"Successfully loaded existing index from {folder_path}."
|
89 |
-
except Exception as e:
|
90 |
-
return f"Error loading index: {str(e)}"
|
91 |
-
|
92 |
-
|
93 |
def chat(message, history):
|
94 |
global vector_store
|
95 |
if vector_store is None:
|
@@ -118,10 +103,6 @@ with gr.Blocks() as demo:
|
|
118 |
with gr.Column():
|
119 |
file_input = gr.File(label="Select Files", file_count="multiple", file_types=[".pdf", ".docx", ".txt"])
|
120 |
process_button = gr.Button("Process Files")
|
121 |
-
with gr.Column():
|
122 |
-
index_folder = gr.Textbox(label="Existing Index Folder Path",
|
123 |
-
value="C:\\Works\\Data\\projects\\Python\\QA_Chatbot\\faiss_index")
|
124 |
-
load_index_button = gr.Button("Load Existing Index")
|
125 |
|
126 |
output = gr.Textbox(label="Processing Output")
|
127 |
|
@@ -138,12 +119,7 @@ with gr.Blocks() as demo:
|
|
138 |
return "No files selected. Please select files and try again."
|
139 |
|
140 |
|
141 |
-
def load_selected_index(folder_path):
|
142 |
-
return load_existing_index(folder_path)
|
143 |
-
|
144 |
-
|
145 |
process_button.click(process_selected_files, file_input, output)
|
146 |
-
load_index_button.click(load_selected_index, index_folder, output)
|
147 |
|
148 |
|
149 |
def respond(message, chat_history):
|
@@ -157,4 +133,4 @@ with gr.Blocks() as demo:
|
|
157 |
clear.click(reset_chat, None, chatbot)
|
158 |
|
159 |
if __name__ == "__main__":
|
160 |
-
demo.launch()
|
|
|
75 |
return f"Embedding process completed and database created. Processed {len(documents)} files. You can now start chatting!"
|
76 |
|
77 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
78 |
def chat(message, history):
|
79 |
global vector_store
|
80 |
if vector_store is None:
|
|
|
103 |
with gr.Column():
|
104 |
file_input = gr.File(label="Select Files", file_count="multiple", file_types=[".pdf", ".docx", ".txt"])
|
105 |
process_button = gr.Button("Process Files")
|
|
|
|
|
|
|
|
|
106 |
|
107 |
output = gr.Textbox(label="Processing Output")
|
108 |
|
|
|
119 |
return "No files selected. Please select files and try again."
|
120 |
|
121 |
|
|
|
|
|
|
|
|
|
122 |
process_button.click(process_selected_files, file_input, output)
|
|
|
123 |
|
124 |
|
125 |
def respond(message, chat_history):
|
|
|
133 |
clear.click(reset_chat, None, chatbot)
|
134 |
|
135 |
if __name__ == "__main__":
|
136 |
+
demo.launch()
|