Spaces:
Running
Running
Upload app.py
Browse files
app.py
CHANGED
|
@@ -1031,6 +1031,16 @@ def _check_and_sync():
|
|
| 1031 |
|
| 1032 |
_check_and_sync()
|
| 1033 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1034 |
|
| 1035 |
# =========================
|
| 1036 |
# 5. 缓存 LLM 客户端
|
|
@@ -1425,7 +1435,11 @@ with st.sidebar:
|
|
| 1425 |
_delete_chunks_by_file(PRIVATE_SCOPE, delete_target)
|
| 1426 |
_delete_uploaded_file_from_storage(PRIVATE_SCOPE, delete_target)
|
| 1427 |
_list_uploaded_files_db.clear()
|
| 1428 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1429 |
st.toast(f"已删除 {delete_target}")
|
| 1430 |
st.rerun()
|
| 1431 |
|
|
@@ -1450,12 +1464,16 @@ with st.sidebar:
|
|
| 1450 |
# 检查是否有待处理的上传(通过 on_change 标记)
|
| 1451 |
if priv_files and st.session_state.pop("_pending_upload_private", False):
|
| 1452 |
process_upload(priv_files, "private", PRIVATE_SCOPE)
|
|
|
|
|
|
|
| 1453 |
|
| 1454 |
if priv_chunk_count > 0 and len(priv_file_list) >= 2:
|
| 1455 |
if st.button("🗑️ 清空我的私有库", use_container_width=True, type="secondary", key="clear_priv"):
|
| 1456 |
_clear_all_chunks(PRIVATE_SCOPE)
|
| 1457 |
_clear_uploaded_files_storage(PRIVATE_SCOPE)
|
| 1458 |
st.session_state["_sync_count_private"] = 0
|
|
|
|
|
|
|
| 1459 |
st.toast("私有知识库已清空")
|
| 1460 |
st.rerun()
|
| 1461 |
|
|
|
|
| 1031 |
|
| 1032 |
_check_and_sync()
|
| 1033 |
|
| 1034 |
+
# --- 登录用户自动模式切换:根据知识库内容决定默认模式 ---
|
| 1035 |
+
if not IS_GUEST and "sel_web" not in st.session_state:
|
| 1036 |
+
# 首次加载时,检查私有库是否有内容
|
| 1037 |
+
priv_count = st.session_state.get("_sync_count_private")
|
| 1038 |
+
if priv_count is None:
|
| 1039 |
+
priv_count = _count_chunks(PRIVATE_SCOPE)
|
| 1040 |
+
st.session_state["_sync_count_private"] = priv_count
|
| 1041 |
+
# 有内容则默认知识库模式,否则联网模式
|
| 1042 |
+
st.session_state["sel_web"] = (priv_count == 0)
|
| 1043 |
+
|
| 1044 |
|
| 1045 |
# =========================
|
| 1046 |
# 5. 缓存 LLM 客户端
|
|
|
|
| 1435 |
_delete_chunks_by_file(PRIVATE_SCOPE, delete_target)
|
| 1436 |
_delete_uploaded_file_from_storage(PRIVATE_SCOPE, delete_target)
|
| 1437 |
_list_uploaded_files_db.clear()
|
| 1438 |
+
new_count = _count_chunks(PRIVATE_SCOPE)
|
| 1439 |
+
st.session_state["_sync_count_private"] = new_count
|
| 1440 |
+
# 删除后如果私有库为空,自动切换到联网模式
|
| 1441 |
+
if new_count == 0:
|
| 1442 |
+
st.session_state["sel_web"] = True
|
| 1443 |
st.toast(f"已删除 {delete_target}")
|
| 1444 |
st.rerun()
|
| 1445 |
|
|
|
|
| 1464 |
# 检查是否有待处理的上传(通过 on_change 标记)
|
| 1465 |
if priv_files and st.session_state.pop("_pending_upload_private", False):
|
| 1466 |
process_upload(priv_files, "private", PRIVATE_SCOPE)
|
| 1467 |
+
# 上传文件后自动切换到知识库模式
|
| 1468 |
+
st.session_state["sel_web"] = False
|
| 1469 |
|
| 1470 |
if priv_chunk_count > 0 and len(priv_file_list) >= 2:
|
| 1471 |
if st.button("🗑️ 清空我的私有库", use_container_width=True, type="secondary", key="clear_priv"):
|
| 1472 |
_clear_all_chunks(PRIVATE_SCOPE)
|
| 1473 |
_clear_uploaded_files_storage(PRIVATE_SCOPE)
|
| 1474 |
st.session_state["_sync_count_private"] = 0
|
| 1475 |
+
# 清空后自动切换到联网模式
|
| 1476 |
+
st.session_state["sel_web"] = True
|
| 1477 |
st.toast("私有知识库已清空")
|
| 1478 |
st.rerun()
|
| 1479 |
|