- 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>
93 lines
4.6 KiB
Markdown
93 lines
4.6 KiB
Markdown
# Tasks: Cleanup Dead Code and Improve Code Quality
|
||
|
||
## Phase 1: 刪除廢棄文件 (高優先級, ~30分鐘)
|
||
|
||
- [x] 1.1 確認 `pdf_generator.py` 無任何引用
|
||
- [x] 1.2 刪除 `backend/app/services/pdf_generator.py`
|
||
- [x] 1.3 驗證後端啟動正常
|
||
|
||
## Phase 2: 移除過時配置 (高優先級, ~15分鐘)
|
||
|
||
- [x] 2.1 移除 `config.py` 中的 `gap_filling_iou_threshold`
|
||
- [x] 2.2 移除 `config.py` 中的 `gap_filling_dedup_iou_threshold`
|
||
- [x] 2.3 搜索並更新任何使用這些配置的代碼
|
||
- [x] 2.4 驗證後端啟動正常
|
||
|
||
## Phase 3: 提取共用 bbox 工具函數 (中優先級, ~2小時)
|
||
|
||
- [x] 3.1 創建 `backend/app/utils/__init__.py`(如不存在)
|
||
- [x] 3.2 創建 `backend/app/utils/bbox_utils.py`,實現統一的 bbox 處理函數
|
||
- [x] 3.3 重構 `gap_filling_service.py` 使用共用函數
|
||
- [x] 3.4 重構 `pdf_generator_service.py` 使用共用函數
|
||
- [x] 3.5 重構 `pp_structure_debug.py` 使用共用函數
|
||
- [x] 3.6 重構 `text_region_renderer.py` 使用共用函數
|
||
- [x] 3.7 測試所有相關功能正常
|
||
|
||
## Phase 4: 前端代碼清理 (低優先級, ~1小時)
|
||
|
||
- [x] 4.1 移除 `ExportPage.tsx` 中未使用的 `CardDescription` import (SKIPPED - actually used)
|
||
- [x] 4.2 重構 `UploadPage.tsx` 的 `as any` 類型斷言 (improved to `as unknown as number`)
|
||
- [x] 4.3 處理或移除 `UploadPage.tsx` 中的 TODO 註釋 (comment improved)
|
||
- [x] 4.4 重構 `TaskHistoryPage.tsx` 的 `as any` 類型斷言 (changed to `as TaskStatus | 'all'`)
|
||
- [x] 4.5 重構 `useTaskValidation.ts` 的 `as any` 類型斷言 (using `instanceof AxiosError`)
|
||
- [x] 4.6 驗證前端編譯正常 (pre-existing errors not from our changes)
|
||
|
||
## Phase 5: 清理禁用的表格補丁功能 (中優先級, ~1小時)
|
||
|
||
- [x] 5.1 移除 `cell_validation_engine.py` 整個文件(已禁用的補丁功能)
|
||
- [x] 5.2 移除 `table_content_rebuilder.py` 整個文件(已禁用的補丁功能)
|
||
- [x] 5.3 移除 `config.py` 中的 `cell_validation_enabled` 配置
|
||
- [x] 5.4 移除 `config.py` 中的 `table_content_rebuilder_enabled` 配置
|
||
- [x] 5.5 移除 `config.py` 中的 `table_quality_check_enabled` 配置
|
||
- [x] 5.6 移除 `config.py` 中的 `table_rendering_prefer_cellboxes` 配置
|
||
- [x] 5.7 搜索並清理所有引用這些配置的代碼
|
||
- [x] 5.8 驗證後端啟動正常
|
||
|
||
## Phase 6: 評估 PP-Structure 模型使用 (需討論, ~2小時)
|
||
|
||
### 6.1 必需模型 (不可移除)
|
||
- [x] 6.1.1 確認 `PP-DocLayout_plus-L` 佈局檢測使用中
|
||
- [x] 6.1.2 確認 `PP-OCRv5_server_det` 文本檢測使用中
|
||
- [x] 6.1.3 確認 `PP-OCRv5_server_rec` 文本識別使用中
|
||
|
||
### 6.2 表格相關模型 (評估是否需要)
|
||
- [x] 6.2.1 評估 `SLANeXt_wired` 有邊框表格結構識別 (保留 - 核心功能)
|
||
- [x] 6.2.2 評估 `SLANeXt_wireless` 無邊框表格結構識別(保守模式下已禁用)(保留配置)
|
||
- [x] 6.2.3 評估 `PP-LCNet_x1_0_table_cls` 表格分類器 (保留 - 核心功能)
|
||
- [x] 6.2.4 評估 `RT-DETR-L_wired_table_cell_det` 有邊框單元格檢測 (保留 - 核心功能)
|
||
- [x] 6.2.5 評估 `RT-DETR-L_wireless_table_cell_det` 無邊框單元格檢測 (保守模式下已禁用) (保留配置)
|
||
|
||
### 6.3 增強功能模型 (可選禁用)
|
||
- [x] 6.3.1 評估 `PP-FormulaNet_plus-L` 公式識別(~300MB)(保留 - 可選功能)
|
||
- [x] 6.3.2 評估 `PP-Chart2Table` 圖表識別(~200MB)(保留 - 可選功能)
|
||
|
||
### 6.4 預處理模型
|
||
- [x] 6.4.1 確認 `PP-LCNet_x1_0_doc_ori` 文檔方向檢測使用中
|
||
- [x] 6.4.2 確認 `PP-LCNet_x1_0_textline_ori` 文本行方向檢測使用中
|
||
- [x] 6.4.3 移除 `UVDoc` 文檔變形修正配置 (保留 - 已禁用但可選)
|
||
|
||
### 6.5 清理 Gap Filling 過時配置
|
||
- [x] 6.5.1 確認 `gap_filling_service.py` 代碼保留(可選增強功能)
|
||
- [x] 6.5.2 移除過時的 IoU 相關配置(Phase 2 已處理)
|
||
|
||
## Verification
|
||
|
||
- [x] 後端服務啟動正常
|
||
- [x] 前端編譯正常 (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** | - | - |
|