github-actions[bot] commited on
Commit ·
4b2c656
1
Parent(s): d4ed2a5
Sync from GitHub: 1cb3988f8558cd7c7ec8e62c67906f3ffc8cd8e1
Browse files- frontend/src/components/ResultCard.jsx +39 -1
- inference.py +16 -1
frontend/src/components/ResultCard.jsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 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);
|
|
@@ -11,6 +11,7 @@ const ResultCard = ({ result, imageData, processedImageData, onReprocess, isProc
|
|
| 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) => {
|
|
@@ -253,6 +254,43 @@ const ResultCard = ({ result, imageData, processedImageData, onReprocess, isProc
|
|
| 253 |
<span>100% (Best)</span>
|
| 254 |
</div>
|
| 255 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
<div className="relative bg-gray-50 rounded-lg p-4 flex justify-center items-center">
|
| 257 |
<canvas ref={canvasRef} className="max-w-full h-auto rounded shadow-md" />
|
| 258 |
{isProcessing && (
|
|
|
|
| 1 |
import React, { useRef, useEffect, useState } from 'react';
|
| 2 |
+
import { SlidersHorizontal, Download, Eye } from 'lucide-react';
|
| 3 |
|
| 4 |
const ResultCard = ({ result, imageData, processedImageData, onReprocess, isProcessing }) => {
|
| 5 |
const canvasRef = useRef(null);
|
|
|
|
| 11 |
const [adjustedDataUrl, setAdjustedDataUrl] = useState(null);
|
| 12 |
const [previewDimensions, setPreviewDimensions] = useState({ width: 0, height: 0 });
|
| 13 |
const [currentImageData, setCurrentImageData] = useState(processedImageData || imageData);
|
| 14 |
+
const [showEnhanced, setShowEnhanced] = useState(false);
|
| 15 |
|
| 16 |
// Function to crop image regions
|
| 17 |
const cropRegion = (img, coords, scaleX, scaleY) => {
|
|
|
|
| 254 |
<span>100% (Best)</span>
|
| 255 |
</div>
|
| 256 |
</div>
|
| 257 |
+
|
| 258 |
+
{/* Enhanced Image Toggle & Download */}
|
| 259 |
+
{result.image_enhanced && result.enhanced_image && (
|
| 260 |
+
<div className="bg-green-50 rounded-lg p-4 shadow-sm border border-green-200">
|
| 261 |
+
<div className="flex items-center justify-between mb-2">
|
| 262 |
+
<div className="flex items-center gap-2">
|
| 263 |
+
<svg className="w-5 h-5 text-green-600" fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
| 264 |
+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z" />
|
| 265 |
+
</svg>
|
| 266 |
+
<span className="text-sm font-medium text-green-800">Image Enhanced (2x)</span>
|
| 267 |
+
</div>
|
| 268 |
+
<div className="flex gap-2">
|
| 269 |
+
<button
|
| 270 |
+
onClick={() => {
|
| 271 |
+
const enhancedData = `data:image/png;base64,${result.enhanced_image}`;
|
| 272 |
+
setCurrentImageData(showEnhanced ? imageData : enhancedData);
|
| 273 |
+
setShowEnhanced(!showEnhanced);
|
| 274 |
+
}}
|
| 275 |
+
className="flex items-center gap-1 px-3 py-1 bg-green-600 hover:bg-green-700 text-white rounded text-xs font-medium transition-colors"
|
| 276 |
+
>
|
| 277 |
+
<Eye className="w-3 h-3" />
|
| 278 |
+
{showEnhanced ? 'Show Original' : 'Show Enhanced'}
|
| 279 |
+
</button>
|
| 280 |
+
<a
|
| 281 |
+
href={`data:image/png;base64,${result.enhanced_image}`}
|
| 282 |
+
download={`enhanced_${result.filename || 'invoice'}.png`}
|
| 283 |
+
className="flex items-center gap-1 px-3 py-1 bg-blue-600 hover:bg-blue-700 text-white rounded text-xs font-medium transition-colors"
|
| 284 |
+
>
|
| 285 |
+
<Download className="w-3 h-3" />
|
| 286 |
+
Download
|
| 287 |
+
</a>
|
| 288 |
+
</div>
|
| 289 |
+
</div>
|
| 290 |
+
<p className="text-xs text-green-700">Real-ESRGAN enhancement applied before processing</p>
|
| 291 |
+
</div>
|
| 292 |
+
)}
|
| 293 |
+
|
| 294 |
<div className="relative bg-gray-50 rounded-lg p-4 flex justify-center items-center">
|
| 295 |
<canvas ref={canvasRef} className="max-w-full h-auto rounded shadow-md" />
|
| 296 |
{isProcessing && (
|
inference.py
CHANGED
|
@@ -343,6 +343,19 @@ class InferenceProcessor:
|
|
| 343 |
image, enhanced_image_path = InferenceProcessor.preprocess_image(image_path, enhance=enhance)
|
| 344 |
timing_breakdown['image_preprocessing'] = round(time.time() - t1, 3)
|
| 345 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 346 |
# Step 2: YOLO Detection (use enhanced image path for consistency)
|
| 347 |
t2 = time.time()
|
| 348 |
signature_info, stamp_info, signature_conf, stamp_conf = model_manager.detect_sign_stamp(enhanced_image_path)
|
|
@@ -399,7 +412,9 @@ class InferenceProcessor:
|
|
| 399 |
"processing_time_sec": round(total_time, 2),
|
| 400 |
"timing_breakdown": timing_breakdown,
|
| 401 |
"cost_estimate_usd": round(cost_estimate, 6),
|
| 402 |
-
"warnings": warnings if warnings else None
|
|
|
|
|
|
|
| 403 |
}
|
| 404 |
|
| 405 |
return result
|
|
|
|
| 343 |
image, enhanced_image_path = InferenceProcessor.preprocess_image(image_path, enhance=enhance)
|
| 344 |
timing_breakdown['image_preprocessing'] = round(time.time() - t1, 3)
|
| 345 |
|
| 346 |
+
# Save enhanced image info for response
|
| 347 |
+
image_was_enhanced = (enhanced_image_path != image_path)
|
| 348 |
+
enhanced_image_base64 = None
|
| 349 |
+
|
| 350 |
+
if image_was_enhanced:
|
| 351 |
+
# Convert enhanced image to base64 for response
|
| 352 |
+
import base64
|
| 353 |
+
try:
|
| 354 |
+
with open(enhanced_image_path, 'rb') as f:
|
| 355 |
+
enhanced_image_base64 = base64.b64encode(f.read()).decode('utf-8')
|
| 356 |
+
except:
|
| 357 |
+
pass
|
| 358 |
+
|
| 359 |
# Step 2: YOLO Detection (use enhanced image path for consistency)
|
| 360 |
t2 = time.time()
|
| 361 |
signature_info, stamp_info, signature_conf, stamp_conf = model_manager.detect_sign_stamp(enhanced_image_path)
|
|
|
|
| 412 |
"processing_time_sec": round(total_time, 2),
|
| 413 |
"timing_breakdown": timing_breakdown,
|
| 414 |
"cost_estimate_usd": round(cost_estimate, 6),
|
| 415 |
+
"warnings": warnings if warnings else None,
|
| 416 |
+
"image_enhanced": image_was_enhanced,
|
| 417 |
+
"enhanced_image": enhanced_image_base64 if image_was_enhanced else None
|
| 418 |
}
|
| 419 |
|
| 420 |
return result
|