Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(model): add HTML minification to StructTableModel #855

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions magic_pdf/model/pek_sub_modules/structeqtable/StructTableModel.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

import torch
from struct_eqtable import build_model

Expand Down Expand Up @@ -28,4 +30,16 @@ def predict(self, images, output_format=None, **kwargs):
images, output_format=output_format
)

if output_format == "html":
results = [self.minify_html(html) for html in results]

return results

def minify_html(self, html):
# 移除多余的空白字符
html = re.sub(r'\s+', ' ', html)
# 移除行尾的空白字符
html = re.sub(r'\s*>\s*', '>', html)
# 移除标签前的空白字符
html = re.sub(r'\s*<\s*', '<', html)
return html.strip()
Loading