Commit dbaff73d authored by wuzekai's avatar wuzekai

Update ocr.py

parent ac820e3f
Pipeline #577 canceled with stages
......@@ -84,4 +84,26 @@ def ocr_inference():
except subprocess.CalledProcessError as e:
return jsonify({"error": f"OCR subprocess failed: {e}"}), 500
except Exception as e:
return jsonify({"error": f"Unexpected error: {e}"}), 500
\ No newline at end of file
return jsonify({"error": f"Unexpected error: {e}"}), 500
@ocr.route("/text/<uuid_str>", methods=["GET"])
def get_text(uuid_str):
if not is_valid_uuid(uuid_str):
return jsonify({"error": "Invalid UUID format"}), 400
json_file = os.path.join(output_dir, f"{uuid_str}.json")
if not os.path.exists(json_file):
return jsonify({"error": "JSON file not found"}), 404
try:
with open(json_file, "r", encoding="utf-8") as f:
data = json.load(f)
# 提取所有 text 字段
text_list = [item.get("text", "") for item in data if "text" in item]
return jsonify({
"uuid": uuid_str,
"content": text_list
}), 200
except Exception as e:
return jsonify({"error": f"Failed to read JSON file: {str(e)}"}), 500
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment