Commit dad42587 authored by myhloli's avatar myhloli
Browse files

Merge remote-tracking branch 'origin/master'

parents 4d6dcb00 351078f1
import pytest import pytest
import os import os
from conf import conf from conf import conf
import subprocess import os
import json
from magic_pdf.pipe.UNIPipe import UNIPipe
from magic_pdf.rw.DiskReaderWriter import DiskReaderWriter
from lib import common from lib import common
import logging
pdf_res_path = conf.conf["pdf_res_path"] pdf_res_path = conf.conf["pdf_res_path"]
code_path = conf.conf["code_path"] code_path = conf.conf["code_path"]
pdf_dev_path = conf.conf["pdf_dev_path"] pdf_dev_path = conf.conf["pdf_dev_path"]
class TestCli: class TestCli:
"""
def test_pdf_specify_dir(self): test cli
"""
def test_pdf_sdk(self):
""" """
输入pdf和指定目录的模型结果 pdf sdk 方式解析
""" """
cmd = 'cd %s && export PYTHONPATH=. && find %s -type f -name "*.pdf" | xargs -I{} python magic_pdf/cli/magicpdf.py pdf-command --pdf {}' % (code_path, pdf_dev_path) demo_names = list()
logging.info(cmd) pdf_path = os.path.join(pdf_dev_path, "pdf")
common.check_shell(cmd) for pdf_file in os.listdir(pdf_path):
#common.count_folders_and_check_contents(pdf_res_path) if pdf_file.endswith('.pdf'):
demo_names.append(pdf_file.split('.')[0])
for demo_name in demo_names:
model_path = os.path.join(pdf_dev_path, f"{demo_name}_model.json")
pdf_path = os.path.join(pdf_dev_path, "pdf", f"{demo_name}.pdf")
pdf_bytes = open(pdf_path, "rb").read()
model_json = json.loads(open(model_path, "r", encoding="utf-8").read())
image_writer = DiskReaderWriter(pdf_dev_path)
image_dir = str(os.path.basename(pdf_dev_path))
jso_useful_key = {"_pdf_type": "", "model_list": model_json}
pipe = UNIPipe(pdf_bytes, jso_useful_key, image_writer)
pipe.pipe_classify()
pipe.pipe_parse()
md_content = pipe.pipe_mk_markdown(image_dir, drop_mode="none")
dir_path = os.path.join(pdf_dev_path, "mineru")
if not os.path.exists(dir_path):
os.makedirs(dir_path, exist_ok=True)
res_path = os.path.join(dir_path, f"{demo_name}.md")
with open(res_path, "w+", encoding="utf-8") as f:
f.write(md_content)
common.count_folders_and_check_contents(res_path)
# def test_pdf_specify_jsonl(self): # def test_pdf_specify_jsonl(self):
# """ # """
# 输入jsonl, 默认方式解析 # 输入jsonl, 默认方式解析
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment