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

Dev #1459

Merged
merged 4 commits into from
Jan 9, 2025
Merged

Dev #1459

Show file tree
Hide file tree
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
12 changes: 4 additions & 8 deletions magic_pdf/model/sub_modules/language_detection/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ def get_model_config():
config_path = os.path.join(model_config_dir, 'model_configs.yaml')
with open(config_path, 'r', encoding='utf-8') as f:
configs = yaml.load(f, Loader=yaml.FullLoader)
return local_models_dir, device, configs
return root_dir, local_models_dir, device, configs


def get_text_images(simple_images):
local_models_dir, device, configs = get_model_config()
_, local_models_dir, device, configs = get_model_config()
atom_model_manager = AtomModelSingleton()
temp_layout_model = atom_model_manager.get_atom_model(
atom_model_name=AtomicModel.Layout,
Expand Down Expand Up @@ -69,15 +69,11 @@ def model_init(model_name: str):
atom_model_manager = AtomModelSingleton()

if model_name == MODEL_NAME.YOLO_V11_LangDetect:
local_models_dir, device, configs = get_model_config()
root_dir, _, device, _ = get_model_config()
model = atom_model_manager.get_atom_model(
atom_model_name=AtomicModel.LangDetect,
langdetect_model_name=MODEL_NAME.YOLO_V11_LangDetect,
langdetect_model_weight=str(
os.path.join(
local_models_dir, configs['weights'][MODEL_NAME.YOLO_V11_LangDetect]
)
),
langdetect_model_weight=str(os.path.join(root_dir, 'resources', 'yolov11-langdetect', 'yolo_v11_ft.pt')),
device=device,
)
else:
Expand Down
5 changes: 5 additions & 0 deletions magic_pdf/pdf_parse_union_core_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -768,6 +768,11 @@ def parse_page_core(
"""重排block"""
sorted_blocks = sorted(fix_blocks, key=lambda b: b['index'])

"""block内重排(img和table的block内多个caption或footnote的排序)"""
for block in sorted_blocks:
if block['type'] in [BlockType.Image, BlockType.Table]:
block['blocks'] = sorted(block['blocks'], key=lambda b: b['index'])

"""获取QA需要外置的list"""
images, tables, interline_equations = get_qa_need_list_v2(sorted_blocks)

Expand Down
3 changes: 1 addition & 2 deletions magic_pdf/resources/model_config/model_configs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ weights:
unimernet_small: MFR/unimernet_small
struct_eqtable: TabRec/StructEqTable
tablemaster: TabRec/TableMaster
rapid_table: TabRec/RapidTable
yolo_v11n_langdetect: LangDetect/YOLO/yolo_v11_ft.pt
rapid_table: TabRec/RapidTable
Binary file not shown.
Binary file modified projects/gradio_app/examples/complex_layout.pdf
100755 → 100644
Binary file not shown.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def parse_requirements(filename):
"doclayout_yolo==0.0.2", # doclayout_yolo
"rapidocr-paddle", # rapidocr-paddle
"rapidocr_onnxruntime",
"rapid_table", # rapid_table
"rapid_table==0.3.0", # rapid_table
"PyYAML", # yaml
"openai", # openai SDK
"detectron2"
Expand Down
Loading