diff --git a/frontend/src/components/PreprocessingPreview.tsx b/frontend/src/components/PreprocessingPreview.tsx index 3527fac..9319ca1 100644 --- a/frontend/src/components/PreprocessingPreview.tsx +++ b/frontend/src/components/PreprocessingPreview.tsx @@ -16,7 +16,6 @@ interface PreprocessingPreviewProps { config: PreprocessingConfig page?: number className?: string - onAutoConfigReceived?: (config: PreprocessingConfig) => void } export default function PreprocessingPreview({ @@ -25,7 +24,6 @@ export default function PreprocessingPreview({ config, page = 1, className, - onAutoConfigReceived, }: PreprocessingPreviewProps) { const { t } = useTranslation() const [isLoading, setIsLoading] = useState(false) @@ -81,18 +79,13 @@ export default function PreprocessingPreview({ setOriginalImageUrl(URL.createObjectURL(originalBlob)) setPreprocessedImageUrl(URL.createObjectURL(preprocessedBlob)) - - // Pass auto config to parent if available - if (response.auto_config && onAutoConfigReceived) { - onAutoConfigReceived(response.auto_config) - } } catch (err: any) { console.error('Preview fetch error:', err) setError(err.response?.data?.detail || err.message || 'Failed to load preview') } finally { setIsLoading(false) } - }, [taskId, debouncedMode, debouncedConfig, page, onAutoConfigReceived]) + }, [taskId, debouncedMode, debouncedConfig, page]) useEffect(() => { fetchPreview() diff --git a/frontend/src/pages/ProcessingPage.tsx b/frontend/src/pages/ProcessingPage.tsx index 5f245fa..b8d29e5 100644 --- a/frontend/src/pages/ProcessingPage.tsx +++ b/frontend/src/pages/ProcessingPage.tsx @@ -1,20 +1,20 @@ import { useState, useEffect } from 'react' import { useNavigate } from 'react-router-dom' import { useTranslation } from 'react-i18next' -import { useMutation } from '@tanstack/react-query' +import { useMutation, useQuery } from '@tanstack/react-query' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { Progress } from '@/components/ui/progress' import { Button } from '@/components/ui/button' import { Badge } from '@/components/ui/badge' import { useToast } from '@/components/ui/toast' import { apiClientV2 } from '@/services/apiV2' -import { Play, CheckCircle, FileText, AlertCircle, Clock, Activity, Loader2 } from 'lucide-react' +import { Play, CheckCircle, FileText, AlertCircle, Clock, Activity, Loader2, Info } from 'lucide-react' import LayoutModelSelector from '@/components/LayoutModelSelector' import PreprocessingSettings from '@/components/PreprocessingSettings' import PreprocessingPreview from '@/components/PreprocessingPreview' import TaskNotFound from '@/components/TaskNotFound' import { useTaskValidation } from '@/hooks/useTaskValidation' -import type { LayoutModel, ProcessingOptions, PreprocessingMode, PreprocessingConfig } from '@/types/apiV2' +import type { LayoutModel, ProcessingOptions, PreprocessingMode, PreprocessingConfig, DocumentAnalysisResponse } from '@/types/apiV2' export default function ProcessingPage() { const { t } = useTranslation() @@ -47,6 +47,20 @@ export default function ProcessingPage() { }) const [showPreview, setShowPreview] = useState(false) + // Analyze document to determine if OCR is needed (only for pending tasks) + const { data: documentAnalysis, isLoading: isAnalyzing } = useQuery({ + queryKey: ['documentAnalysis', taskId], + queryFn: () => apiClientV2.analyzeDocument(taskId!), + enabled: !!taskId && taskDetail?.status === 'pending', + staleTime: Infinity, // Cache indefinitely since document doesn't change + }) + + // Determine if preprocessing options should be shown + // Only show for OCR track files (images and non-editable PDFs) + const needsOcrTrack = documentAnalysis?.recommended_track === 'ocr' || + documentAnalysis?.recommended_track === 'hybrid' || + !documentAnalysis // Show by default while analyzing + // Start OCR processing const processOCRMutation = useMutation({ mutationFn: () => { @@ -360,36 +374,66 @@ export default function ProcessingPage() { {/* Processing Options (only show when task is pending) */} {isPending && (
- {/* Layout Model Selection */} - + {/* Document Analysis Loading */} + {isAnalyzing && ( +
+ + 分析文件類型中... +
+ )} - {/* Preprocessing Settings */} - setShowPreview(!showPreview)} - disabled={processOCRMutation.isPending} - /> + {/* Direct Track Notice - Show when document is editable PDF */} + {documentAnalysis && documentAnalysis.recommended_track === 'direct' && ( + + +
+ +
+

此文件為可編輯 PDF

+

+ 系統偵測到此 PDF 包含文字圖層,將使用直接文字提取方式處理。 + 版面偵測和影像前處理設定不適用於此類文件。 +

+ {documentAnalysis.text_coverage && ( +

+ 文字覆蓋率: {(documentAnalysis.text_coverage * 100).toFixed(1)}% +

+ )} +
+
+
+
+ )} - {/* Preprocessing Preview */} - {showPreview && taskId && ( - { - // Only update if user hasn't switched to manual mode - if (preprocessingMode === 'auto') { - setPreprocessingConfig(autoConfig) - } - }} - /> + {/* OCR Track Options - Only show when document needs OCR */} + {needsOcrTrack && !isAnalyzing && ( + <> + {/* Layout Model Selection */} + + + {/* Preprocessing Settings */} + setShowPreview(!showPreview)} + disabled={processOCRMutation.isPending} + /> + + {/* Preprocessing Preview */} + {showPreview && taskId && ( + + )} + )}
)}