jslmmfboom-coder commited on
Commit
e601def
·
1 Parent(s): 7347923

Fix: demo skip classify_scene, fix unpack error, fix cover path, update track name

Browse files
Files changed (3) hide show
  1. app.py +12 -12
  2. index.html +3 -3
  3. module/text_classifier.py +15 -0
app.py CHANGED
@@ -758,22 +758,20 @@ async def demo(scene_type: str = Form("auto")):
758
 
759
 
760
  def _run_demo_pipeline(img_paths, expected_scene):
761
- """执行示例检测流程(不涉及用户历史数据,纯两张图比对)"""
 
 
 
762
  import cv2
763
  import numpy as np
764
 
765
  path1, path2 = img_paths[0], img_paths[1]
766
 
767
- # 场景分类第一张图)
 
768
  ocr_result = None
769
  full_text = ''
770
- try:
771
- scene_type, detail = classify_scene(path1, ocr_engine)
772
- ocr_result = detail.get('ocr_result')
773
- full_text = detail.get('full_text', '')
774
- except Exception as e:
775
- scene_type = expected_scene
776
- print(f"[demo] 场景分类失败: {e}")
777
 
778
  is_same = False
779
  similarity = 0.0
@@ -792,9 +790,11 @@ def _run_demo_pipeline(img_paths, expected_scene):
792
  # 文本场景:OCR + BGE 比对
793
  from module.text_matcher import compute_text_similarity
794
  try:
795
- # OCR 第二张图
796
- scene2, detail2 = classify_scene(path2, ocr_engine)
797
- text2 = detail2.get('full_text', '')
 
 
798
  log_entry['history_text'] = text2
799
 
800
  # BGE 编码比对
 
758
 
759
 
760
  def _run_demo_pipeline(img_paths, expected_scene):
761
+ """执行示例检测流程(不涉及用户历史数据,纯两张图比对)
762
+
763
+ expected_scene 直接指定场景类型,跳过 classify_scene 节省时间
764
+ """
765
  import cv2
766
  import numpy as np
767
 
768
  path1, path2 = img_paths[0], img_paths[1]
769
 
770
+ # 跳过场景分类,直接使 expected_scene
771
+ scene_type = expected_scene
772
  ocr_result = None
773
  full_text = ''
774
+ print(f"[demo] 跳过场景分类,直接使用指定场景: {scene_type}")
 
 
 
 
 
 
775
 
776
  is_same = False
777
  similarity = 0.0
 
790
  # 文本场景:OCR + BGE 比对
791
  from module.text_matcher import compute_text_similarity
792
  try:
793
+ # 直接 OCR 提取两张图文本,跳过 classify_scene
794
+ from module.text_classifier import _ocr_image
795
+ full_text = _ocr_image(path1, ocr_engine) or ''
796
+ text2 = _ocr_image(path2, ocr_engine) or ''
797
+ log_entry['query_text'] = full_text
798
  log_entry['history_text'] = text2
799
 
800
  # BGE 编码比对
index.html CHANGED
@@ -32,7 +32,7 @@ body{
32
  /* === 背景图 cover.png === */
33
  .bg-cover{
34
  position:fixed;inset:0;z-index:-3;
35
- background-image:url('/cover.png');
36
  background-size:cover;background-position:center;
37
  opacity:0.35;
38
  }
@@ -78,7 +78,7 @@ body{
78
  }
79
  .parallax-bg .bg-cover-inner{
80
  position:absolute;inset:0;
81
- background-image:url('/cover.png');
82
  background-size:cover;background-position:center;
83
  opacity:0.3;
84
  }
@@ -352,7 +352,7 @@ tr.row-fail td{color:#ef9a9a}
352
 
353
  <!-- 报名信息头 -->
354
  <div class="about-header-card">
355
- <div class="track">报名赛道:造个新解法 — 聚焦新一代学习工作方式</div>
356
  <h1>慧眼同源</h1>
357
  <div class="tagline">多模态文档去重与版本溯源系统</div>
358
  </div>
 
32
  /* === 背景图 cover.png === */
33
  .bg-cover{
34
  position:fixed;inset:0;z-index:-3;
35
+ background-image:url('cover.png');
36
  background-size:cover;background-position:center;
37
  opacity:0.35;
38
  }
 
78
  }
79
  .parallax-bg .bg-cover-inner{
80
  position:absolute;inset:0;
81
+ background-image:url('cover.png');
82
  background-size:cover;background-position:center;
83
  opacity:0.3;
84
  }
 
352
 
353
  <!-- 报名信息头 -->
354
  <div class="about-header-card">
355
+ <div class="track">报名赛道:学习工作赛道</div>
356
  <h1>慧眼同源</h1>
357
  <div class="tagline">多模态文档去重与版本溯源系统</div>
358
  </div>
module/text_classifier.py CHANGED
@@ -84,6 +84,21 @@ def _compute_line_density(text_boxes, img_shape):
84
  return float(density_norm)
85
 
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
  def classify_scene(image_path, ocr_engine, doc_score_threshold=DOC_SCORE_THRESHOLD,
88
  precomputed_ocr_result=None):
89
  """多信号加权评分判断图片属于文本场景还是复杂场景
 
84
  return float(density_norm)
85
 
86
 
87
+ def _ocr_image(image_path, ocr_engine):
88
+ """仅执行 OCR 提取文本,不做场景分类
89
+
90
+ Returns:
91
+ full_text: 提取的文本字符串
92
+ """
93
+ try:
94
+ result = ocr_engine.ocr(image_path, cls=True)
95
+ if result and result[0]:
96
+ return ' '.join(line[1][0] for line in result[0])
97
+ except Exception as e:
98
+ print(f"[OCR] 提取失败: {e}")
99
+ return ''
100
+
101
+
102
  def classify_scene(image_path, ocr_engine, doc_score_threshold=DOC_SCORE_THRESHOLD,
103
  precomputed_ocr_result=None):
104
  """多信号加权评分判断图片属于文本场景还是复杂场景