From bc64b1c718425a798c02e50beebc8d11c5ac5f08 Mon Sep 17 00:00:00 2001 From: Nicole Rappe Date: Fri, 30 May 2025 01:37:09 -0600 Subject: [PATCH] Upgraded OCR Text Extraction Node --- .../Node_OCR_Text_Extraction.jsx | 189 ++++++++---------- 1 file changed, 84 insertions(+), 105 deletions(-) diff --git a/Data/Server/WebUI/src/nodes/Data Analysis & Manipulation/Node_OCR_Text_Extraction.jsx b/Data/Server/WebUI/src/nodes/Data Analysis & Manipulation/Node_OCR_Text_Extraction.jsx index c9b2cc8..cb53df3 100644 --- a/Data/Server/WebUI/src/nodes/Data Analysis & Manipulation/Node_OCR_Text_Extraction.jsx +++ b/Data/Server/WebUI/src/nodes/Data Analysis & Manipulation/Node_OCR_Text_Extraction.jsx @@ -1,9 +1,9 @@ -////////// PROJECT FILE SEPARATION LINE ////////// CODE AFTER THIS LINE ARE FROM: Node_OCR_Text_Extraction.jsx +////////// PROJECT FILE SEPARATION LINE ////////// CODE AFTER THIS LINE ARE FROM: /Data/WebUI/src/nodes/Image Processing/Node_OCR_Text_Extraction.jsx import React, { useEffect, useState, useRef } from "react"; import { Handle, Position, useReactFlow, useStore } from "reactflow"; -// Base64 comparison using hash (lightweight) +// Lightweight hash for image change detection const getHashScore = (str = "") => { let hash = 0; for (let i = 0; i < str.length; i += 101) { @@ -22,43 +22,22 @@ const OCRNode = ({ id, data }) => { const { setNodes } = useReactFlow(); const [ocrOutput, setOcrOutput] = useState(""); - const [engine, setEngine] = useState(data?.engine || "None"); - const [backend, setBackend] = useState(data?.backend || "CPU"); - const [dataType, setDataType] = useState(data?.dataType || "Mixed"); - const [customRateEnabled, setCustomRateEnabled] = useState(data?.customRateEnabled ?? true); - const [customRateMs, setCustomRateMs] = useState(data?.customRateMs || 1000); - const [changeThreshold, setChangeThreshold] = useState(data?.changeThreshold || 0); - const valueRef = useRef(""); const lastUsed = useRef({ engine: "", backend: "", dataType: "" }); const lastProcessedAt = useRef(0); const lastImageHash = useRef(0); - // Sync updated settings back into node.data for persistence - useEffect(() => { - setNodes((nodes) => - nodes.map((n) => - n.id === id - ? { - ...n, - data: { - ...n.data, - engine, - backend, - dataType, - customRateEnabled, - customRateMs, - changeThreshold - } - } - : n - ) - ); - }, [engine, backend, dataType, customRateEnabled, customRateMs, changeThreshold]); + // Always get config from props (sidebar sets these in node.data) + const engine = data?.engine || "None"; + const backend = data?.backend || "CPU"; + const dataType = data?.dataType || "Mixed"; + const customRateEnabled = data?.customRateEnabled ?? true; + const customRateMs = data?.customRateMs || 1000; + const changeThreshold = data?.changeThreshold || 0; + // OCR API Call const sendToOCRAPI = async (base64) => { const cleanBase64 = base64.replace(/^data:image\/[a-zA-Z]+;base64,/, ""); - try { const response = await fetch("/api/ocr", { method: "POST", @@ -74,6 +53,7 @@ const OCRNode = ({ id, data }) => { } }; + // Filter lines based on user type const filterLines = (lines) => { if (dataType === "Numerical") { return lines.map(line => line.replace(/[^\d.%\s]/g, '').replace(/\s+/g, ' ').trim()).filter(Boolean); @@ -149,57 +129,6 @@ const OCRNode = ({ id, data }) => {
Extract Multi-Line Text from Upstream Image Node
- - - - - - - - - - - -
- setCustomRateEnabled(e.target.checked)} - style={{ marginRight: "8px" }} - /> - setCustomRateMs(Number(e.target.value))} - disabled={!customRateEnabled} - style={numberInputStyle} - /> -
- - - setChangeThreshold(Number(e.target.value))} - style={numberInputStyle} - /> -