Spaces:
Sleeping
Sleeping
nihuajian
commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -101,20 +101,35 @@ def clean_formula_output(text):
|
|
| 101 |
|
| 102 |
def clean_text_output(text):
|
| 103 |
"""清理输出文本,只保留识别的文字内容"""
|
| 104 |
-
lines = text.strip().split('\n')
|
| 105 |
-
text_lines = []
|
| 106 |
-
|
| 107 |
# 移除代码块标记
|
| 108 |
cleaned_text = text.replace('```text', '').replace('```', '').strip()
|
| 109 |
lines = cleaned_text.split('\n')
|
| 110 |
|
|
|
|
| 111 |
for line in lines:
|
| 112 |
line = line.strip()
|
| 113 |
-
#
|
| 114 |
if line and not any(line.startswith(prefix) for prefix in [
|
| 115 |
-
'图片中的文字', '识别结果', '文字内容', '根据图片', '这张图片', '该图片'
|
|
|
|
| 116 |
]):
|
| 117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
|
| 119 |
return '\n'.join(text_lines)
|
| 120 |
|
|
|
|
| 101 |
|
| 102 |
def clean_text_output(text):
|
| 103 |
"""清理输出文本,只保留识别的文字内容"""
|
|
|
|
|
|
|
|
|
|
| 104 |
# 移除代码块标记
|
| 105 |
cleaned_text = text.replace('```text', '').replace('```', '').strip()
|
| 106 |
lines = cleaned_text.split('\n')
|
| 107 |
|
| 108 |
+
text_lines = []
|
| 109 |
for line in lines:
|
| 110 |
line = line.strip()
|
| 111 |
+
# 跳过解释性文字和标签信息
|
| 112 |
if line and not any(line.startswith(prefix) for prefix in [
|
| 113 |
+
'图片中的文字', '识别结果', '文字内容', '根据图片', '这张图片', '该图片',
|
| 114 |
+
'标题:', '正文:', '内容:', '文本:', '题目:', '段落:', '文字:'
|
| 115 |
]):
|
| 116 |
+
# 移除行首的标签格式(如 "标题:内容" -> "内容")
|
| 117 |
+
if ':' in line:
|
| 118 |
+
# 检查是否是标签格式
|
| 119 |
+
parts = line.split(':', 1)
|
| 120 |
+
if len(parts) == 2 and len(parts[0]) <= 10: # 标签通常很短
|
| 121 |
+
# 可能的标签词
|
| 122 |
+
label_keywords = ['标题', '正文', '内容', '文本', '题目', '段落', '文字', '主题', '副标题']
|
| 123 |
+
if any(keyword in parts[0] for keyword in label_keywords):
|
| 124 |
+
# 只保留标签后的内容
|
| 125 |
+
text_lines.append(parts[1].strip())
|
| 126 |
+
else:
|
| 127 |
+
# 不是标签格式,保留整行
|
| 128 |
+
text_lines.append(line)
|
| 129 |
+
else:
|
| 130 |
+
text_lines.append(line)
|
| 131 |
+
else:
|
| 132 |
+
text_lines.append(line)
|
| 133 |
|
| 134 |
return '\n'.join(text_lines)
|
| 135 |
|