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

text_level is always just 1 in magic_pdf but not in deployed version on huggingface #1584

Closed
SaidKhudoyan opened this issue Jan 20, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@SaidKhudoyan
Copy link

Description of the bug | 错误描述

Hi, when running pdf extraction with magic-pdf the text_level is always just 1. However, when testing the online version on Huggingface, the text_levels are correctly shown. Is there any difference between the deployed version and the open-source python-api or is that just an erro?

How to reproduce the bug | 如何复现

Just install magic-pdf and try to run below code on some example pdf document.

os.environ["MINERU_TOOLS_CONFIG_JSON"] = os.path.join(os.path.dirname(os.path.abspath(__file__)), "magic-pdf.json")
from magic_pdf.data.data_reader_writer import FileBasedDataWriter, FileBasedDataReader
from magic_pdf.data.dataset import PymuDocDataset
from magic_pdf.model.doc_analyze_by_custom_model import doc_analyze
from magic_pdf.config.enums import SupportedPdfParseMethod

def extract_pdf_content(pdf_file_path):
    output_dir = "Output"
    image_dir = os.path.join(output_dir, "images")
    os.makedirs(image_dir, exist_ok=True)
    image_writer = FileBasedDataWriter(image_dir)
    output_writer = FileBasedDataWriter(output_dir)
    reader = FileBasedDataReader("")
    pdf_bytes = reader.read(pdf_file_path)
    ds = PymuDocDataset(pdf_bytes)
    if ds.classify() == SupportedPdfParseMethod.OCR:
        infer_result = ds.apply(doc_analyze, ocr=True)
        pipe_result = infer_result.pipe_ocr_mode(image_writer)
    else:
        infer_result = ds.apply(doc_analyze, ocr=False)
        pipe_result = infer_result.pipe_txt_mode(image_writer)
    
    relative_image_dir = "images"  # Relativer Pfad für JSON-Referenzen
    pipe_result.dump_content_list(output_writer, "content_list.json", relative_image_dir)

if __name__ == "__main__":
    pdf_file = "ExamplePDF"  # Ihr PDF-Dateiname
    extract_pdf_content(pdf_file)

Operating system | 操作系统

Linux

Python version | Python 版本

3.10

Software version | 软件版本 (magic-pdf --version)

1.0.x

Device mode | 设备模式

cpu

@SaidKhudoyan SaidKhudoyan added the bug Something isn't working label Jan 20, 2025
@myhloli
Copy link
Collaborator

myhloli commented Jan 20, 2025

Title classification is currently a preview feature, available only on the online demo for testing accuracy and stability. It will be officially released in the stable version once the feature matures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants