重构文本提取功能,简化图像文本处理流程

This commit is contained in:
Zylan
2025-03-05 23:20:47 +08:00
parent 80829f09d2
commit 5bb8b4ea2d
4 changed files with 102 additions and 63 deletions

15
app.py
View File

@@ -222,13 +222,14 @@ def handle_text_extraction(data):
api_key=mathpix_key
)
print("Starting text extraction thread...")
extraction_thread = Thread(
target=stream_model_response,
args=(model.analyze_image(image_data), request.sid)
)
extraction_thread.daemon = True # Make thread daemon so it doesn't block shutdown
extraction_thread.start()
print("Starting text extraction...")
# 使用新的extract_full_text方法直接提取完整文本
extracted_text = model.extract_full_text(image_data)
# 直接返回文本结果
socketio.emit('text_extracted', {
'content': extracted_text
}, room=request.sid)
except ValueError as e:
error_msg = str(e)