quick_demo.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. #!/usr/bin/env python3
  2. """
  3. 表格验证功能快速验证脚本
  4. 验证升级后的表格详细分析功能
  5. """
  6. import json
  7. import os
  8. from typing import Dict, Any
  9. from ocr_verification import verify_ocr_with_vlm, analyze_differences
  10. def quick_table_verification_demo():
  11. """快速演示表格验证功能"""
  12. print("🚀 表格详细验证功能演示")
  13. print("=" * 50)
  14. # 检查必要文件
  15. ocr_file = "demo_54fa7ad0_page_1.json"
  16. image_file = "至远彩色印刷工业有限公司-2022年母公司_2.png"
  17. if not os.path.exists(ocr_file):
  18. print(f"❌ 找不到OCR文件: {ocr_file}")
  19. return
  20. if not os.path.exists(image_file):
  21. print(f"❌ 找不到图片文件: {image_file}")
  22. return
  23. print(f"✅ 文件检查完成")
  24. print(f"📄 OCR文件: {ocr_file}")
  25. print(f"🖼️ 图片文件: {image_file}")
  26. print()
  27. # 演示不同精度级别的验证
  28. verification_modes = [
  29. {
  30. "name": "🎯 高精度模式(推荐用于财务报表)",
  31. "config": {
  32. "temperature": 0.05,
  33. "max_tokens": 8192,
  34. "timeout": 400
  35. }
  36. },
  37. {
  38. "name": "⚖️ 平衡模式(一般表格)",
  39. "config": {
  40. "temperature": 0.15,
  41. "max_tokens": 4096,
  42. "timeout": 240
  43. }
  44. },
  45. {
  46. "name": "⚡ 快速模式(初步扫描)",
  47. "config": {
  48. "temperature": 0.25,
  49. "max_tokens": 2048,
  50. "timeout": 120
  51. }
  52. }
  53. ]
  54. for i, mode in enumerate(verification_modes, 1):
  55. print(f"\n📊 测试 {i}/3: {mode['name']}")
  56. print("-" * 40)
  57. try:
  58. output_file = f"verification_result_mode_{i}.json"
  59. print(f"🔍 开始验证...")
  60. print(f" 温度参数: {mode['config']['temperature']}")
  61. print(f" 最大Token: {mode['config']['max_tokens']}")
  62. print(f" 超时时间: {mode['config']['timeout']}秒")
  63. # 执行验证
  64. result = verify_ocr_with_vlm(
  65. image_file,
  66. ocr_file,
  67. output_file,
  68. **mode['config']
  69. )
  70. if result:
  71. print(f"✅ 验证完成,结果保存到: {output_file}")
  72. # 显示关键指标
  73. if isinstance(result, dict):
  74. print(f"📈 关键指标:")
  75. # 显示表格验证信息
  76. table_info = result.get('table_verification', {})
  77. if table_info:
  78. print(f" 检查项目: {table_info.get('total_items_checked', 'N/A')}")
  79. print(f" 准确率: {table_info.get('accuracy_rate', 'N/A')}")
  80. print(f" 结构正确: {'✅' if table_info.get('table_structure_correct') else '❌'}")
  81. # 显示错误统计
  82. errors = result.get('errors', [])
  83. format_issues = result.get('format_issues', [])
  84. missing_items = result.get('missing_items', [])
  85. print(f" 识别错误: {len(errors)} 项")
  86. print(f" 格式问题: {len(format_issues)} 项")
  87. print(f" 遗漏项目: {len(missing_items)} 项")
  88. # 显示高严重程度错误
  89. critical_errors = [
  90. error for error in errors
  91. if error.get('severity') == '高'
  92. ]
  93. if critical_errors:
  94. print(f" 🔴 高严重程度错误: {len(critical_errors)} 项")
  95. else:
  96. print(f"❌ 验证失败")
  97. except Exception as e:
  98. print(f"❌ 验证过程出错: {str(e)}")
  99. continue
  100. print(f"\n🎯 演示完成!")
  101. print(f"📁 查看生成的结果文件:")
  102. for i in range(1, 4):
  103. result_file = f"verification_result_mode_{i}.json"
  104. if os.path.exists(result_file):
  105. print(f" 📄 {result_file}")
  106. print(f"\n💡 使用建议:")
  107. print(f" 🎯 财务报表 → 使用高精度模式")
  108. print(f" ⚖️ 一般表格 → 使用平衡模式")
  109. print(f" ⚡ 快速检查 → 使用快速模式")
  110. # 分析最后一个结果
  111. if os.path.exists("verification_result_mode_1.json"):
  112. print(f"\n🔍 分析高精度模式结果:")
  113. try:
  114. analyze_differences("verification_result_mode_1.json")
  115. except Exception as e:
  116. print(f"❌ 分析出错: {str(e)}")
  117. def show_table_analysis_capabilities():
  118. """展示表格分析能力说明"""
  119. print(f"\n📋 新增表格分析能力:")
  120. print("=" * 50)
  121. capabilities = [
  122. "🔍 逐项验证: 对表格中每个数据项进行单独验证",
  123. "📊 格式检查: 检测千分符、小数点、标点符号错误",
  124. "🏗️ 结构验证: 验证表格行列对应关系",
  125. "📈 完整性检查: 确保重要项目和数据不遗漏",
  126. "🎯 错误分级: 高/中/低严重程度分类",
  127. "📍 精确定位: 提供行X列Y的具体位置信息",
  128. "💡 修正建议: 给出具体的错误修正方案",
  129. "📊 统计报告: 准确率、错误分布等指标",
  130. "🔧 参数优化: 支持多种精度模式配置"
  131. ]
  132. for capability in capabilities:
  133. print(f" {capability}")
  134. print(f"\n📄 支持的表格类型:")
  135. table_types = [
  136. "💰 财务报表 (利润表、资产负债表、现金流量表)",
  137. "📊 数据统计表 (业务数据、运营指标)",
  138. "📋 清单表格 (物料清单、人员名单)",
  139. "📈 对比分析表 (同比、环比数据)",
  140. "🗓️ 时间序列表 (月度、季度、年度数据)"
  141. ]
  142. for table_type in table_types:
  143. print(f" {table_type}")
  144. if __name__ == "__main__":
  145. # 显示功能说明
  146. show_table_analysis_capabilities()
  147. # 执行演示
  148. quick_table_verification_demo()