Spaces:
Sleeping
Sleeping
jslmmfboom-coder commited on
Commit ·
4c16f88
1
Parent(s): 789241f
Fix: clean Qdrant cache when history empty, remove retest button
Browse files- app.py +8 -0
- index.html +1 -3
- module/qdrant_manager.py +16 -0
app.py
CHANGED
|
@@ -422,6 +422,14 @@ async def detect(
|
|
| 422 |
uploaded_paths = [p for _, p in saved_info]
|
| 423 |
|
| 424 |
if len(history_before) == 0:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 425 |
per_image_results = {p: '通过(首次上传,跳过比对)' for _, p in saved_info}
|
| 426 |
update_metadata(user_dir, saved_info, per_image_results)
|
| 427 |
try:
|
|
|
|
| 422 |
uploaded_paths = [p for _, p in saved_info]
|
| 423 |
|
| 424 |
if len(history_before) == 0:
|
| 425 |
+
# 清理可能的 Qdrant 残留数据(用户可能通过历史管理删除了所有图片)
|
| 426 |
+
try:
|
| 427 |
+
from module.qdrant_manager import qdrant_delete_user_collections
|
| 428 |
+
qdrant_delete_user_collections(uname)
|
| 429 |
+
except Exception:
|
| 430 |
+
pass
|
| 431 |
+
_qd_caches.pop(uname, None)
|
| 432 |
+
|
| 433 |
per_image_results = {p: '通过(首次上传,跳过比对)' for _, p in saved_info}
|
| 434 |
update_metadata(user_dir, saved_info, per_image_results)
|
| 435 |
try:
|
index.html
CHANGED
|
@@ -678,9 +678,7 @@ function renderResult(data) {
|
|
| 678 |
}
|
| 679 |
}
|
| 680 |
|
| 681 |
-
//
|
| 682 |
-
html += `<div style="text-align:center;margin:20px 0"><button class="btn btn-primary" onclick="document.getElementById('resultArea').innerHTML='';document.getElementById('queryInput').value='';document.getElementById('queryFileList').innerHTML='';document.getElementById('uploadSection').classList.remove('hidden');isDemoMode=false;">🔄 再测一张</button></div>`;
|
| 683 |
-
|
| 684 |
resultArea.innerHTML = html;
|
| 685 |
}
|
| 686 |
|
|
|
|
| 678 |
}
|
| 679 |
}
|
| 680 |
|
| 681 |
+
// 上传区域始终可见,用户可随时重新选择图片上传
|
|
|
|
|
|
|
| 682 |
resultArea.innerHTML = html;
|
| 683 |
}
|
| 684 |
|
module/qdrant_manager.py
CHANGED
|
@@ -136,6 +136,22 @@ def qdrant_query_scene(username, scene_type):
|
|
| 136 |
return cache
|
| 137 |
|
| 138 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
# ==================== 向量相似度搜索 ====================
|
| 140 |
|
| 141 |
def qdrant_search_similar(username, scene_type, query_vector, top_k=3, score_threshold=0.0):
|
|
|
|
| 136 |
return cache
|
| 137 |
|
| 138 |
|
| 139 |
+
def qdrant_delete_user_collections(username):
|
| 140 |
+
"""删除指定用户的所有 Qdrant collection(text + complex)
|
| 141 |
+
|
| 142 |
+
用于用户历史库为空时清理残留数据
|
| 143 |
+
"""
|
| 144 |
+
client = _get_client()
|
| 145 |
+
for scene_type in ('text', 'complex'):
|
| 146 |
+
cname = _collection_name(username, scene_type)
|
| 147 |
+
try:
|
| 148 |
+
if client.collection_exists(cname):
|
| 149 |
+
client.delete_collection(cname)
|
| 150 |
+
print(f"[Qdrant] 已删除 collection: {cname}")
|
| 151 |
+
except Exception as e:
|
| 152 |
+
print(f"[Qdrant] 删除 collection {cname} 失败: {e}")
|
| 153 |
+
|
| 154 |
+
|
| 155 |
# ==================== 向量相似度搜索 ====================
|
| 156 |
|
| 157 |
def qdrant_search_similar(username, scene_type, query_vector, top_k=3, score_threshold=0.0):
|