v2
This commit is contained in:
parent
f6099c312e
commit
4c0bc822cb
BIN
sample_images/1755692193_1__.jpg
Normal file
BIN
sample_images/1755692193_1__.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 171 KiB |
BIN
sample_images/1755692193_2__.jpg
Normal file
BIN
sample_images/1755692193_2__.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 109 KiB |
BIN
sample_images/1755692193_3__.jpg
Normal file
BIN
sample_images/1755692193_3__.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 111 KiB |
BIN
sample_images/1755692193_4__.jpg
Normal file
BIN
sample_images/1755692193_4__.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 189 KiB |
BIN
sample_images/1755692193_5__.jpg
Normal file
BIN
sample_images/1755692193_5__.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 201 KiB |
BIN
uploads/query_1755692249_2__.jpg
Normal file
BIN
uploads/query_1755692249_2__.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 109 KiB |
@ -173,9 +173,39 @@ def handle_search(mode):
|
|||||||
|
|
||||||
# 执行搜索
|
# 执行搜索
|
||||||
if mode == 'text_to_text':
|
if mode == 'text_to_text':
|
||||||
results = retrieval_system.search_text_to_text(query, top_k=top_k)
|
raw_results = retrieval_system.search_text_to_text(query, top_k=top_k)
|
||||||
|
# 格式化文本搜索结果
|
||||||
|
results = []
|
||||||
|
for text, score in raw_results:
|
||||||
|
results.append({
|
||||||
|
'text': text,
|
||||||
|
'score': float(score)
|
||||||
|
})
|
||||||
else: # text_to_image
|
else: # text_to_image
|
||||||
results = retrieval_system.search_text_to_image(query, top_k=top_k)
|
raw_results = retrieval_system.search_text_to_image(query, top_k=top_k)
|
||||||
|
# 格式化图像搜索结果
|
||||||
|
results = []
|
||||||
|
for image_path, score in raw_results:
|
||||||
|
try:
|
||||||
|
# 读取图像并转换为base64
|
||||||
|
with open(image_path, 'rb') as img_file:
|
||||||
|
image_data = img_file.read()
|
||||||
|
image_base64 = base64.b64encode(image_data).decode('utf-8')
|
||||||
|
|
||||||
|
results.append({
|
||||||
|
'filename': os.path.basename(image_path),
|
||||||
|
'image_path': image_path,
|
||||||
|
'image_base64': image_base64,
|
||||||
|
'score': float(score)
|
||||||
|
})
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"读取图像失败 {image_path}: {e}")
|
||||||
|
results.append({
|
||||||
|
'filename': os.path.basename(image_path),
|
||||||
|
'image_path': image_path,
|
||||||
|
'image_base64': '',
|
||||||
|
'score': float(score)
|
||||||
|
})
|
||||||
|
|
||||||
return jsonify({
|
return jsonify({
|
||||||
'success': True,
|
'success': True,
|
||||||
@ -211,9 +241,39 @@ def handle_search(mode):
|
|||||||
|
|
||||||
# 执行搜索
|
# 执行搜索
|
||||||
if mode == 'image_to_text':
|
if mode == 'image_to_text':
|
||||||
results = retrieval_system.search_image_to_text(filepath, top_k=top_k)
|
raw_results = retrieval_system.search_image_to_text(filepath, top_k=top_k)
|
||||||
|
# 格式化文本搜索结果
|
||||||
|
results = []
|
||||||
|
for text, score in raw_results:
|
||||||
|
results.append({
|
||||||
|
'text': text,
|
||||||
|
'score': float(score)
|
||||||
|
})
|
||||||
else: # image_to_image
|
else: # image_to_image
|
||||||
results = retrieval_system.search_image_to_image(filepath, top_k=top_k)
|
raw_results = retrieval_system.search_image_to_image(filepath, top_k=top_k)
|
||||||
|
# 格式化图像搜索结果
|
||||||
|
results = []
|
||||||
|
for image_path, score in raw_results:
|
||||||
|
try:
|
||||||
|
# 读取图像并转换为base64
|
||||||
|
with open(image_path, 'rb') as img_file:
|
||||||
|
image_data = img_file.read()
|
||||||
|
image_base64 = base64.b64encode(image_data).decode('utf-8')
|
||||||
|
|
||||||
|
results.append({
|
||||||
|
'filename': os.path.basename(image_path),
|
||||||
|
'image_path': image_path,
|
||||||
|
'image_base64': image_base64,
|
||||||
|
'score': float(score)
|
||||||
|
})
|
||||||
|
except Exception as e:
|
||||||
|
logger.error(f"读取图像失败 {image_path}: {e}")
|
||||||
|
results.append({
|
||||||
|
'filename': os.path.basename(image_path),
|
||||||
|
'image_path': image_path,
|
||||||
|
'image_base64': '',
|
||||||
|
'score': float(score)
|
||||||
|
})
|
||||||
|
|
||||||
# 转换查询图片为base64
|
# 转换查询图片为base64
|
||||||
query_image_b64 = image_to_base64(filepath)
|
query_image_b64 = image_to_base64(filepath)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user