- Enable PP-StructureV3's use_doc_orientation_classify feature - Detect rotation angle from doc_preprocessor_res.angle - Swap page dimensions (width <-> height) for 90°/270° rotations - Output PDF now correctly displays landscape-scanned content Also includes: - Archive completed openspec proposals - Add simplify-frontend-ocr-config proposal (pending) - Code cleanup and frontend simplification 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
4.6 KiB
4.6 KiB
Tasks: Cleanup Dead Code and Improve Code Quality
Phase 1: 刪除廢棄文件 (高優先級, ~30分鐘)
- 1.1 確認
pdf_generator.py無任何引用 - 1.2 刪除
backend/app/services/pdf_generator.py - 1.3 驗證後端啟動正常
Phase 2: 移除過時配置 (高優先級, ~15分鐘)
- 2.1 移除
config.py中的gap_filling_iou_threshold - 2.2 移除
config.py中的gap_filling_dedup_iou_threshold - 2.3 搜索並更新任何使用這些配置的代碼
- 2.4 驗證後端啟動正常
Phase 3: 提取共用 bbox 工具函數 (中優先級, ~2小時)
- 3.1 創建
backend/app/utils/__init__.py(如不存在) - 3.2 創建
backend/app/utils/bbox_utils.py,實現統一的 bbox 處理函數 - 3.3 重構
gap_filling_service.py使用共用函數 - 3.4 重構
pdf_generator_service.py使用共用函數 - 3.5 重構
pp_structure_debug.py使用共用函數 - 3.6 重構
text_region_renderer.py使用共用函數 - 3.7 測試所有相關功能正常
Phase 4: 前端代碼清理 (低優先級, ~1小時)
- 4.1 移除
ExportPage.tsx中未使用的CardDescriptionimport (SKIPPED - actually used) - 4.2 重構
UploadPage.tsx的as any類型斷言 (improved toas unknown as number) - 4.3 處理或移除
UploadPage.tsx中的 TODO 註釋 (comment improved) - 4.4 重構
TaskHistoryPage.tsx的as any類型斷言 (changed toas TaskStatus | 'all') - 4.5 重構
useTaskValidation.ts的as any類型斷言 (usinginstanceof AxiosError) - 4.6 驗證前端編譯正常 (pre-existing errors not from our changes)
Phase 5: 清理禁用的表格補丁功能 (中優先級, ~1小時)
- 5.1 移除
cell_validation_engine.py整個文件(已禁用的補丁功能) - 5.2 移除
table_content_rebuilder.py整個文件(已禁用的補丁功能) - 5.3 移除
config.py中的cell_validation_enabled配置 - 5.4 移除
config.py中的table_content_rebuilder_enabled配置 - 5.5 移除
config.py中的table_quality_check_enabled配置 - 5.6 移除
config.py中的table_rendering_prefer_cellboxes配置 - 5.7 搜索並清理所有引用這些配置的代碼
- 5.8 驗證後端啟動正常
Phase 6: 評估 PP-Structure 模型使用 (需討論, ~2小時)
6.1 必需模型 (不可移除)
- 6.1.1 確認
PP-DocLayout_plus-L佈局檢測使用中 - 6.1.2 確認
PP-OCRv5_server_det文本檢測使用中 - 6.1.3 確認
PP-OCRv5_server_rec文本識別使用中
6.2 表格相關模型 (評估是否需要)
- 6.2.1 評估
SLANeXt_wired有邊框表格結構識別 (保留 - 核心功能) - 6.2.2 評估
SLANeXt_wireless無邊框表格結構識別(保守模式下已禁用)(保留配置) - 6.2.3 評估
PP-LCNet_x1_0_table_cls表格分類器 (保留 - 核心功能) - 6.2.4 評估
RT-DETR-L_wired_table_cell_det有邊框單元格檢測 (保留 - 核心功能) - 6.2.5 評估
RT-DETR-L_wireless_table_cell_det無邊框單元格檢測 (保守模式下已禁用) (保留配置)
6.3 增強功能模型 (可選禁用)
- 6.3.1 評估
PP-FormulaNet_plus-L公式識別(~300MB)(保留 - 可選功能) - 6.3.2 評估
PP-Chart2Table圖表識別(~200MB)(保留 - 可選功能)
6.4 預處理模型
- 6.4.1 確認
PP-LCNet_x1_0_doc_ori文檔方向檢測使用中 - 6.4.2 確認
PP-LCNet_x1_0_textline_ori文本行方向檢測使用中 - 6.4.3 移除
UVDoc文檔變形修正配置 (保留 - 已禁用但可選)
6.5 清理 Gap Filling 過時配置
- 6.5.1 確認
gap_filling_service.py代碼保留(可選增強功能) - 6.5.2 移除過時的 IoU 相關配置(Phase 2 已處理)
Verification
- 後端服務啟動正常
- 前端編譯正常 (pre-existing TypeScript errors not from our changes)
- OCR 處理功能正常(Direct Track + OCR Track)- 需手動測試
- PDF 生成功能正常 - 需手動測試
- 表格渲染功能正常(conservative 模式)- 需手動測試
- GPU 記憶體使用正常 - 需手動測試
Summary
| Phase | 實際刪除行數 | 複雜度 | 說明 |
|---|---|---|---|
| Phase 1 | 507 | 低 | 刪除廢棄的 pdf_generator.py |
| Phase 2 | ~10 | 低 | 移除過時 IoU 配置及引用 |
| Phase 3 | ~80 (節省重複) | 中 | 提取共用 bbox 工具,新增 bbox_utils.py |
| Phase 4 | ~5 | 低 | 前端類型改進 |
| Phase 5 | ~1,450 | 中 | 清理禁用的補丁功能 (583+806+configs) |
| Phase 6 | 0 | 低 | 評估完成,保留模型配置 |
| Total | ~2,050 | - | - |