Implemented OCR Functionality

This commit is contained in:
2025-04-13 03:08:07 -06:00
parent 85b8a7d052
commit c741d81a45
120 changed files with 17416 additions and 6 deletions

View File

@ -4,6 +4,10 @@ import time
import os
import base64
# Borealis Python API Endpoints
# These are Python files that run code to process data given to them via the API
from Python_API_Endpoints.ocr_engines import run_ocr_on_base64
# ---------------------------------------------
# React Frontend Hosting Configuration
# ---------------------------------------------
@ -28,6 +32,31 @@ def serve_react_app(path):
return send_from_directory(build_folder, path)
return send_from_directory(build_folder, "index.html")
# ---------------------------------------------
# Borealis Python API Endpoints
# ---------------------------------------------
# Process image data into OCR text output.
@app.route("/api/ocr", methods=["POST"])
def ocr_endpoint():
payload = request.get_json()
image_b64 = payload.get("image_base64")
engine = payload.get("engine", "tesseract").lower().strip()
backend = payload.get("backend", "cpu").lower().strip()
# Normalize engine aliases
if engine in ["tesseractocr", "tesseract"]:
engine = "tesseract"
elif engine == "easyocr":
engine = "easyocr"
else:
return jsonify({"error": f"OCR engine '{engine}' not recognized."}), 400
try:
lines = run_ocr_on_base64(image_b64, engine=engine, backend=backend)
return jsonify({"lines": lines})
except Exception as e:
return jsonify({"error": str(e)}), 500
# ---------------------------------------------
# Borealis Agent API Endpoints
# ---------------------------------------------