test
This commit is contained in:
@@ -8,14 +8,15 @@ 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, Info } from 'lucide-react'
|
||||
import { Play, CheckCircle, FileText, AlertCircle, Clock, Activity, Loader2 } from 'lucide-react'
|
||||
import LayoutModelSelector from '@/components/LayoutModelSelector'
|
||||
import PreprocessingSettings from '@/components/PreprocessingSettings'
|
||||
import PreprocessingPreview from '@/components/PreprocessingPreview'
|
||||
import TableDetectionSelector from '@/components/TableDetectionSelector'
|
||||
import ProcessingTrackSelector from '@/components/ProcessingTrackSelector'
|
||||
import TaskNotFound from '@/components/TaskNotFound'
|
||||
import { useTaskValidation } from '@/hooks/useTaskValidation'
|
||||
import type { LayoutModel, ProcessingOptions, PreprocessingMode, PreprocessingConfig, TableDetectionConfig, DocumentAnalysisResponse } from '@/types/apiV2'
|
||||
import type { LayoutModel, ProcessingOptions, PreprocessingMode, PreprocessingConfig, TableDetectionConfig, ProcessingTrack } from '@/types/apiV2'
|
||||
|
||||
export default function ProcessingPage() {
|
||||
const { t } = useTranslation()
|
||||
@@ -56,6 +57,9 @@ export default function ProcessingPage() {
|
||||
enable_region_detection: true,
|
||||
})
|
||||
|
||||
// Processing track override state (null = use system recommendation)
|
||||
const [forceTrack, setForceTrack] = useState<ProcessingTrack | null>(null)
|
||||
|
||||
// Analyze document to determine if OCR is needed (only for pending tasks)
|
||||
const { data: documentAnalysis, isLoading: isAnalyzing } = useQuery({
|
||||
queryKey: ['documentAnalysis', taskId],
|
||||
@@ -65,16 +69,23 @@ export default function ProcessingPage() {
|
||||
})
|
||||
|
||||
// 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
|
||||
// Show OCR options when:
|
||||
// 1. User explicitly selected OCR track
|
||||
// 2. OR system recommends OCR/hybrid track (and user hasn't overridden to direct)
|
||||
// 3. OR still analyzing (show by default)
|
||||
const needsOcrTrack = forceTrack === 'ocr' ||
|
||||
(forceTrack === null && (
|
||||
documentAnalysis?.recommended_track === 'ocr' ||
|
||||
documentAnalysis?.recommended_track === 'hybrid' ||
|
||||
!documentAnalysis
|
||||
))
|
||||
|
||||
// Start OCR processing
|
||||
const processOCRMutation = useMutation({
|
||||
mutationFn: () => {
|
||||
const options: ProcessingOptions = {
|
||||
use_dual_track: true,
|
||||
use_dual_track: forceTrack === null, // Only use dual-track auto-detection if not forcing
|
||||
force_track: forceTrack || undefined, // Pass force_track if user selected one
|
||||
language: 'ch',
|
||||
layout_model: layoutModel,
|
||||
preprocessing_mode: preprocessingMode,
|
||||
@@ -392,53 +403,14 @@ export default function ProcessingPage() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Document Analysis Info */}
|
||||
{documentAnalysis && (
|
||||
<Card className={documentAnalysis.recommended_track === 'direct' ? 'border-blue-200 bg-blue-50' : 'border-green-200 bg-green-50'}>
|
||||
<CardContent className="pt-4">
|
||||
<div className="flex items-start gap-3">
|
||||
<Info className={`w-5 h-5 flex-shrink-0 mt-0.5 ${documentAnalysis.recommended_track === 'direct' ? 'text-blue-600' : 'text-green-600'}`} />
|
||||
<div className="flex-1">
|
||||
{documentAnalysis.recommended_track === 'direct' ? (
|
||||
<>
|
||||
<p className="text-sm font-medium text-blue-800">此文件為可編輯 PDF</p>
|
||||
<p className="text-sm text-blue-700 mt-1">
|
||||
系統偵測到此 PDF 包含文字圖層,將使用直接文字提取方式處理。
|
||||
版面偵測和影像前處理設定不適用於此類文件。
|
||||
</p>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<p className="text-sm font-medium text-green-800">
|
||||
{documentAnalysis.is_editable ? '混合文件' : '掃描文件 / 影像'}
|
||||
</p>
|
||||
<p className="text-sm text-green-700 mt-1">
|
||||
{documentAnalysis.reason}
|
||||
</p>
|
||||
</>
|
||||
)}
|
||||
<div className="flex flex-wrap gap-4 mt-2 text-xs">
|
||||
<span className={documentAnalysis.recommended_track === 'direct' ? 'text-blue-600' : 'text-green-600'}>
|
||||
處理方式: {documentAnalysis.recommended_track === 'direct' ? '直接提取' : documentAnalysis.recommended_track === 'ocr' ? 'OCR 識別' : '混合處理'}
|
||||
</span>
|
||||
{documentAnalysis.page_count && (
|
||||
<span className={documentAnalysis.recommended_track === 'direct' ? 'text-blue-600' : 'text-green-600'}>
|
||||
頁數: {documentAnalysis.page_count}
|
||||
</span>
|
||||
)}
|
||||
{documentAnalysis.text_coverage !== null && (
|
||||
<span className={documentAnalysis.recommended_track === 'direct' ? 'text-blue-600' : 'text-green-600'}>
|
||||
文字覆蓋率: {(documentAnalysis.text_coverage * 100).toFixed(1)}%
|
||||
</span>
|
||||
)}
|
||||
<span className={documentAnalysis.recommended_track === 'direct' ? 'text-blue-600' : 'text-green-600'}>
|
||||
信心度: {(documentAnalysis.confidence * 100).toFixed(0)}%
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
{/* Processing Track Selector - Always show after analysis */}
|
||||
{!isAnalyzing && (
|
||||
<ProcessingTrackSelector
|
||||
value={forceTrack}
|
||||
onChange={setForceTrack}
|
||||
documentAnalysis={documentAnalysis}
|
||||
disabled={processOCRMutation.isPending}
|
||||
/>
|
||||
)}
|
||||
|
||||
{/* OCR Track Options - Only show when document needs OCR */}
|
||||
|
||||
Reference in New Issue
Block a user