github-actions[bot]
commited on
Commit
·
28d65c9
1
Parent(s):
b948e3a
Sync from GitHub: 9ba6bb6324a7e4f6a8cdae6be63edad427949587
Browse files- frontend/src/App.jsx +11 -4
- frontend/src/components/ResultCard.jsx +19 -15
frontend/src/App.jsx
CHANGED
|
@@ -90,7 +90,7 @@ function App() {
|
|
| 90 |
|
| 91 |
try {
|
| 92 |
// Use resolution-adjusted image if available
|
| 93 |
-
const processData = resolutionMap[preview.key] || { dataUrl: preview.dataUrl };
|
| 94 |
const blob = dataUrlToBlob(processData.dataUrl);
|
| 95 |
|
| 96 |
const result = await processSingleInvoice(blob, preview.filename);
|
|
@@ -101,7 +101,9 @@ function App() {
|
|
| 101 |
originalFile: preview.filename,
|
| 102 |
index: i,
|
| 103 |
success: true,
|
| 104 |
-
key: preview.key
|
|
|
|
|
|
|
| 105 |
};
|
| 106 |
|
| 107 |
setResults(prev => [...prev, resultWithMetadata]);
|
|
@@ -146,7 +148,9 @@ function App() {
|
|
| 146 |
originalFile: result.originalFile,
|
| 147 |
index: index,
|
| 148 |
success: true,
|
| 149 |
-
key: result.key
|
|
|
|
|
|
|
| 150 |
};
|
| 151 |
|
| 152 |
setResults(prev => {
|
|
@@ -296,11 +300,14 @@ function App() {
|
|
| 296 |
|
| 297 |
{results.map((result, index) => {
|
| 298 |
const imageKey = result.key || `${result.originalFile}_${index}`;
|
|
|
|
|
|
|
| 299 |
return (
|
| 300 |
<ResultCard
|
| 301 |
key={index}
|
| 302 |
result={result}
|
| 303 |
-
imageData={
|
|
|
|
| 304 |
onReprocess={handleReprocess}
|
| 305 |
isProcessing={processingIndex === index}
|
| 306 |
/>
|
|
|
|
| 90 |
|
| 91 |
try {
|
| 92 |
// Use resolution-adjusted image if available
|
| 93 |
+
const processData = resolutionMap[preview.key] || { dataUrl: preview.dataUrl, resolution: 100 };
|
| 94 |
const blob = dataUrlToBlob(processData.dataUrl);
|
| 95 |
|
| 96 |
const result = await processSingleInvoice(blob, preview.filename);
|
|
|
|
| 101 |
originalFile: preview.filename,
|
| 102 |
index: i,
|
| 103 |
success: true,
|
| 104 |
+
key: preview.key,
|
| 105 |
+
processedImageData: processData.dataUrl,
|
| 106 |
+
processedResolution: processData.resolution
|
| 107 |
};
|
| 108 |
|
| 109 |
setResults(prev => [...prev, resultWithMetadata]);
|
|
|
|
| 148 |
originalFile: result.originalFile,
|
| 149 |
index: index,
|
| 150 |
success: true,
|
| 151 |
+
key: result.key,
|
| 152 |
+
processedImageData: adjustedDataUrl || imageDataMap[result.key],
|
| 153 |
+
processedResolution: resolution
|
| 154 |
};
|
| 155 |
|
| 156 |
setResults(prev => {
|
|
|
|
| 300 |
|
| 301 |
{results.map((result, index) => {
|
| 302 |
const imageKey = result.key || `${result.originalFile}_${index}`;
|
| 303 |
+
const originalImage = imageDataMap[imageKey] || imageDataMap[Object.keys(imageDataMap)[index]];
|
| 304 |
+
const processedImage = result.processedImageData || originalImage;
|
| 305 |
return (
|
| 306 |
<ResultCard
|
| 307 |
key={index}
|
| 308 |
result={result}
|
| 309 |
+
imageData={originalImage}
|
| 310 |
+
processedImageData={processedImage}
|
| 311 |
onReprocess={handleReprocess}
|
| 312 |
isProcessing={processingIndex === index}
|
| 313 |
/>
|
frontend/src/components/ResultCard.jsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
import React, { useRef, useEffect, useState } from 'react';
|
| 2 |
import { SlidersHorizontal } from 'lucide-react';
|
| 3 |
|
| 4 |
-
const ResultCard = ({ result, imageData, onReprocess, isProcessing }) => {
|
| 5 |
const canvasRef = useRef(null);
|
| 6 |
const previewCanvasRef = useRef(null);
|
| 7 |
const [dimensions, setDimensions] = useState({ width: 0, height: 0 });
|
|
@@ -10,7 +10,7 @@ const ResultCard = ({ result, imageData, onReprocess, isProcessing }) => {
|
|
| 10 |
const [resolution, setResolution] = useState(100);
|
| 11 |
const [adjustedDataUrl, setAdjustedDataUrl] = useState(null);
|
| 12 |
const [previewDimensions, setPreviewDimensions] = useState({ width: 0, height: 0 });
|
| 13 |
-
const [currentImageData, setCurrentImageData] = useState(imageData);
|
| 14 |
|
| 15 |
// Function to crop image regions
|
| 16 |
const cropRegion = (img, coords, scaleX, scaleY) => {
|
|
@@ -35,6 +35,13 @@ const ResultCard = ({ result, imageData, onReprocess, isProcessing }) => {
|
|
| 35 |
return cropCanvas.toDataURL();
|
| 36 |
};
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
// Main effect to draw image with bounding boxes using currentImageData
|
| 39 |
useEffect(() => {
|
| 40 |
if (!currentImageData || !canvasRef.current) return;
|
|
@@ -70,19 +77,16 @@ const ResultCard = ({ result, imageData, onReprocess, isProcessing }) => {
|
|
| 70 |
const scaleX = width / img.width;
|
| 71 |
const scaleY = height / img.height;
|
| 72 |
|
| 73 |
-
// Create cropped images for signature and stamp from
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
}
|
| 84 |
-
};
|
| 85 |
-
originalImg.src = imageData;
|
| 86 |
|
| 87 |
// Draw bounding boxes for signature
|
| 88 |
if (result.signature_coords && result.signature_coords.length > 0) {
|
|
|
|
| 1 |
import React, { useRef, useEffect, useState } from 'react';
|
| 2 |
import { SlidersHorizontal } from 'lucide-react';
|
| 3 |
|
| 4 |
+
const ResultCard = ({ result, imageData, processedImageData, onReprocess, isProcessing }) => {
|
| 5 |
const canvasRef = useRef(null);
|
| 6 |
const previewCanvasRef = useRef(null);
|
| 7 |
const [dimensions, setDimensions] = useState({ width: 0, height: 0 });
|
|
|
|
| 10 |
const [resolution, setResolution] = useState(100);
|
| 11 |
const [adjustedDataUrl, setAdjustedDataUrl] = useState(null);
|
| 12 |
const [previewDimensions, setPreviewDimensions] = useState({ width: 0, height: 0 });
|
| 13 |
+
const [currentImageData, setCurrentImageData] = useState(processedImageData || imageData);
|
| 14 |
|
| 15 |
// Function to crop image regions
|
| 16 |
const cropRegion = (img, coords, scaleX, scaleY) => {
|
|
|
|
| 35 |
return cropCanvas.toDataURL();
|
| 36 |
};
|
| 37 |
|
| 38 |
+
// Initialize currentImageData with processedImageData when available
|
| 39 |
+
useEffect(() => {
|
| 40 |
+
if (processedImageData) {
|
| 41 |
+
setCurrentImageData(processedImageData);
|
| 42 |
+
}
|
| 43 |
+
}, [processedImageData]);
|
| 44 |
+
|
| 45 |
// Main effect to draw image with bounding boxes using currentImageData
|
| 46 |
useEffect(() => {
|
| 47 |
if (!currentImageData || !canvasRef.current) return;
|
|
|
|
| 77 |
const scaleX = width / img.width;
|
| 78 |
const scaleY = height / img.height;
|
| 79 |
|
| 80 |
+
// Create cropped images for signature and stamp from the CURRENT (processed) image
|
| 81 |
+
// This ensures crops match the resolution that was sent to the API
|
| 82 |
+
if (result.signature_coords && result.signature_coords.length > 0) {
|
| 83 |
+
const sigCrop = cropRegion(img, result.signature_coords, 1, 1);
|
| 84 |
+
setSignatureCrop(sigCrop);
|
| 85 |
+
}
|
| 86 |
+
if (result.stamp_coords && result.stamp_coords.length > 0) {
|
| 87 |
+
const stCrop = cropRegion(img, result.stamp_coords, 1, 1);
|
| 88 |
+
setStampCrop(stCrop);
|
| 89 |
+
}
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
// Draw bounding boxes for signature
|
| 92 |
if (result.signature_coords && result.signature_coords.length > 0) {
|