Spaces:
Sleeping
Sleeping
Commit
·
911a4b5
1
Parent(s):
a9e40c2
Fix stale index bug: Force clear dirs and reload singleton. Update UI label.
Browse files- apps/web/app.py +14 -6
apps/web/app.py
CHANGED
|
@@ -90,12 +90,16 @@ def chat_fn(message, history, backend):
|
|
| 90 |
final_response = f"{answer}\n\n{sources_text}\n*(Backend: {backend} | Time: {elapsed:.2f}s)*"
|
| 91 |
return final_response
|
| 92 |
|
|
|
|
| 93 |
def admin_ingest(files, use_sample):
|
| 94 |
-
#
|
| 95 |
temp_in = "temp_ingest"
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
|
|
|
|
|
|
|
|
|
| 99 |
|
| 100 |
status = "Starting ingestion...\n"
|
| 101 |
|
|
@@ -128,8 +132,12 @@ def admin_ingest(files, use_sample):
|
|
| 128 |
status += "Index built successfully.\nReloading services...\n"
|
| 129 |
yield status
|
| 130 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
init_services()
|
| 132 |
-
status += "Services reloaded.
|
| 133 |
except Exception as e:
|
| 134 |
print(f"Ingestion Failed: {e}") # Print to server logs
|
| 135 |
import traceback
|
|
@@ -150,7 +158,7 @@ with gr.Blocks(title="RAG Knowledge Assistant", theme=gr.themes.Soft()) as demo:
|
|
| 150 |
with gr.Column(scale=1, variant="panel"):
|
| 151 |
with gr.Group():
|
| 152 |
file_upload = gr.File(
|
| 153 |
-
label="Upload Docs",
|
| 154 |
file_count="multiple",
|
| 155 |
file_types=[".pdf", ".txt", ".html"],
|
| 156 |
height=70
|
|
|
|
| 90 |
final_response = f"{answer}\n\n{sources_text}\n*(Backend: {backend} | Time: {elapsed:.2f}s)*"
|
| 91 |
return final_response
|
| 92 |
|
| 93 |
+
|
| 94 |
def admin_ingest(files, use_sample):
|
| 95 |
+
# 1. Clean Data & Temp Dirs (Fresh Start)
|
| 96 |
temp_in = "temp_ingest"
|
| 97 |
+
dirs_to_clean = [temp_in, PROCESSED_DIR, INDEX_DIR]
|
| 98 |
+
|
| 99 |
+
for d in dirs_to_clean:
|
| 100 |
+
if os.path.exists(d):
|
| 101 |
+
shutil.rmtree(d)
|
| 102 |
+
os.makedirs(d)
|
| 103 |
|
| 104 |
status = "Starting ingestion...\n"
|
| 105 |
|
|
|
|
| 132 |
status += "Index built successfully.\nReloading services...\n"
|
| 133 |
yield status
|
| 134 |
|
| 135 |
+
# FORCE RELOAD: Clear singletons
|
| 136 |
+
import services.rag.retrieve
|
| 137 |
+
services.rag.retrieve._shared_retriever = None
|
| 138 |
+
|
| 139 |
init_services()
|
| 140 |
+
status += "Services reloaded. Brain Updated! 🧠"
|
| 141 |
except Exception as e:
|
| 142 |
print(f"Ingestion Failed: {e}") # Print to server logs
|
| 143 |
import traceback
|
|
|
|
| 158 |
with gr.Column(scale=1, variant="panel"):
|
| 159 |
with gr.Group():
|
| 160 |
file_upload = gr.File(
|
| 161 |
+
label="Upload Multiple Docs",
|
| 162 |
file_count="multiple",
|
| 163 |
file_types=[".pdf", ".txt", ".html"],
|
| 164 |
height=70
|