Spaces:
Sleeping
Sleeping
Update src/app.py
Browse files- src/app.py +16 -5
src/app.py
CHANGED
|
@@ -290,15 +290,22 @@ with tab2:
|
|
| 290 |
# ACTION BAR
|
| 291 |
col_a, col_b, col_c = st.columns(3)
|
| 292 |
|
| 293 |
-
# 1. ADD TO DB
|
| 294 |
with col_a:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 295 |
if st.button("📥 Add to Knowledge Base", type="primary"):
|
| 296 |
with st.spinner("Ingesting..."):
|
| 297 |
# Use Admin or User Key for Vision
|
| 298 |
key = st.session_state.get("user_openai_key") or OPENAI_KEY
|
| 299 |
|
| 300 |
ok, msg = rag_engine.process_and_add_document(
|
| 301 |
-
temp_path, st.session_state.username,
|
| 302 |
use_vision=use_vision, api_key=key
|
| 303 |
)
|
| 304 |
|
|
@@ -309,6 +316,9 @@ with tab2:
|
|
| 309 |
|
| 310 |
# 2. SUMMARIZE
|
| 311 |
with col_b:
|
|
|
|
|
|
|
|
|
|
| 312 |
if st.button("📝 Summarize Document"):
|
| 313 |
with st.spinner("Reading & Summarizing..."):
|
| 314 |
key = st.session_state.get("user_openai_key") or OPENAI_KEY
|
|
@@ -338,6 +348,10 @@ with tab2:
|
|
| 338 |
|
| 339 |
# 3. FLATTEN
|
| 340 |
with col_c:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 341 |
# We use a session state variable to store the result so it persists for the "Index" step
|
| 342 |
if "flattened_result" not in st.session_state:
|
| 343 |
st.session_state.flattened_result = None
|
|
@@ -394,9 +408,6 @@ with tab2:
|
|
| 394 |
if ok:
|
| 395 |
tracker.upload_user_db(st.session_state.username) # Sync!
|
| 396 |
st.success(msg)
|
| 397 |
-
# Optional: Clear result after adding
|
| 398 |
-
# st.session_state.flattened_result = None
|
| 399 |
-
# st.rerun()
|
| 400 |
else:
|
| 401 |
st.error(msg)
|
| 402 |
|
|
|
|
| 290 |
# ACTION BAR
|
| 291 |
col_a, col_b, col_c = st.columns(3)
|
| 292 |
|
| 293 |
+
# 1. ADD TO DB (With Strategy Selection)
|
| 294 |
with col_a:
|
| 295 |
+
chunk_strategy = st.selectbox(
|
| 296 |
+
"Chunking Strategy",
|
| 297 |
+
["paragraph", "token", "page"],
|
| 298 |
+
help="Paragraph: Standard. Token: Dense text. Page: Forms.",
|
| 299 |
+
key="chunk_selector"
|
| 300 |
+
)
|
| 301 |
+
|
| 302 |
if st.button("📥 Add to Knowledge Base", type="primary"):
|
| 303 |
with st.spinner("Ingesting..."):
|
| 304 |
# Use Admin or User Key for Vision
|
| 305 |
key = st.session_state.get("user_openai_key") or OPENAI_KEY
|
| 306 |
|
| 307 |
ok, msg = rag_engine.process_and_add_document(
|
| 308 |
+
temp_path, st.session_state.username, chunk_strategy, # Pass selected strategy
|
| 309 |
use_vision=use_vision, api_key=key
|
| 310 |
)
|
| 311 |
|
|
|
|
| 316 |
|
| 317 |
# 2. SUMMARIZE
|
| 318 |
with col_b:
|
| 319 |
+
# Spacer to align buttons visually since col_a has a selectbox
|
| 320 |
+
st.write("")
|
| 321 |
+
st.write("")
|
| 322 |
if st.button("📝 Summarize Document"):
|
| 323 |
with st.spinner("Reading & Summarizing..."):
|
| 324 |
key = st.session_state.get("user_openai_key") or OPENAI_KEY
|
|
|
|
| 348 |
|
| 349 |
# 3. FLATTEN
|
| 350 |
with col_c:
|
| 351 |
+
# Spacer to align buttons
|
| 352 |
+
st.write("")
|
| 353 |
+
st.write("")
|
| 354 |
+
|
| 355 |
# We use a session state variable to store the result so it persists for the "Index" step
|
| 356 |
if "flattened_result" not in st.session_state:
|
| 357 |
st.session_state.flattened_result = None
|
|
|
|
| 408 |
if ok:
|
| 409 |
tracker.upload_user_db(st.session_state.username) # Sync!
|
| 410 |
st.success(msg)
|
|
|
|
|
|
|
|
|
|
| 411 |
else:
|
| 412 |
st.error(msg)
|
| 413 |
|