Views
No views yet
MinerU-HTML/
├── mineru_html/ # Core code package
│ ├── __init__.py # Package initialization, exports main API
│ ├── api.py # Main API interfaces (MinerUHTMLGeneric, MinerUHTMLConfig)
│ ├── base.py # Base data class definitions
│ ├── constants.py # Constant definitions
│ ├── exceptions.py # Exception class definitions
│ ├── utils.py # Utility functions
│ ├── implementations/ # Concrete implementation classes
│ │ ├── __init__.py # implementations subpackage initialization file
│ │ ├── vllm_api.py # VLLM API backend implementation (MinerUHTML)
│ │ ├── openai_api.py # OpenAI API backend implementation (MinerUHTML_OpenAI)
│ │ └── transformers_api.py # Transformers API backend implementation (MinerUHTML_Transformers)
│ ├── inference/ # Inference backend abstraction layer
│ │ ├── __init__.py # inference subpackage initialization file
│ │ ├── base_backend.py # Inference backend base class (InferenceBackend)
│ │ ├── factory.py # Backend factory functions
│ │ ├── vllm_backend.py # VLLM backend implementation (VLLMInferenceBackend)
│ │ ├── transformers_backend.py # Transformers backend implementation (TransformersInferenceBackend)
│ │ └── openai_backend.py # OpenAI API backend implementation (OpenaiAPIInferenceBackend)
│ └── process/ # Processing pipeline module
│ ├── __init__.py # process subpackage initialization file
│ ├── build_prompt.py # Prompt construction
│ ├── simplify_html.py # HTML simplification
│ ├── parse_result.py # Result parsing
│ ├── map_to_main.py # Main content extraction
│ └── html_utils.py # HTML utility functions
├── tests/ # Test code
├── benchmark/ # Benchmark test data
├── eval_baselines/ # Benchmark evaluation code
├── requirements/ # Dependency package lists (by module)
│ ├── core.txt # Core dependencies
│ ├── openai.txt # OpenAI related dependencies
│ └── vllm.txt # VLLM related dependencies
├── README.md # Documentation
├── run_eval.sh # Benchmark test execution script
├── baselines.txt # Benchmark dependency package list
├── eval_baselines.py # Benchmark evaluation entry code
└── setup.py # Installation configuration (supports optional dependencies)1pip install .
2# Or development mode
3pip install -e .1# Install OpenAI backend dependencies
2pip install .[openai]
3
4# Install VLLM backend dependencies
5pip install .[vllm]
6
7# Install all dependencies
8pip install .[all]1from mineru_html import MinerUHTML, MinerUHTMLConfig
2
3# Create configuration
4config = MinerUHTMLConfig(
5 use_fall_back='trafilatura', # or 'bypass'
6 prompt_version='compact', # recommend using compact
7 early_load=True
8)
9
10# Initialize MinerUHTML (using local model)
11extractor = MinerUHTML(
12 model_path='path/to/your/model', # The model used must correspond to the prompt_version in MinerUHTMLConfig
13 config=config
14)
15
16# Process single HTML
17html_content = '<html>...</html>'
18result = extractor.process(html_content)
19print(result[0].main_html)
20
21# Process multiple HTML
22html_list = ['<html>...</html>', '<html>...</html>']
23results = extractor.process(html_list)
24for result in results:
25 print(result.main_html)
26 print(result.case_id)1from mineru_html import MinerUHTML_OpenAI, MinerUHTMLConfig
2
3# Create configuration
4config = MinerUHTMLConfig(
5 use_fall_back='trafilatura',
6 prompt_version='v2', # Recommend using v2
7 early_load=True
8)
9
10# Initialize MinerUHTML_OpenAI
11extractor = MinerUHTML_OpenAI(
12 base_url='https://api.openai.com/v1',
13 sk='your-api-key',
14 model='gpt-5',
15 config=config,
16 retry_times=3
17)
18
19# Process HTML
20html_content = '<html>...</html>'
21result = extractor.process(html_content)
22print(result[0].main_html)1from mineru_html import MinerUHTML_Transformers, MinerUHTMLConfig
2
3# Create configuration
4config = MinerUHTMLConfig(
5 use_fall_back='trafilatura',
6 prompt_version='v2',
7 early_load=True
8)
9
10# Initialize MinerUHTML_Transformers
11extractor = MinerUHTML_Transformers(
12 model_path='path/to/your/model', # The model used must correspond to the prompt_version in MinerUHTMLConfig
13 config=config,
14 model_init_kwargs={
15 'device_map': 'auto',
16 'dtype': 'auto',
17 },
18 model_gen_kwargs={
19 'max_new_tokens': 8192,
20 }
21)
22
23# Process HTML
24html_content = '<html>...</html>'
25result = extractor.process(html_content)
26print(result[0].main_html)simplify_html): Simplifies raw HTML into a structured format, assigning a unique _item_id attribute to each elementbuild_prompt): Constructs LLM prompts based on simplified HTML to guide the model in content classificationinference): Uses LLM to classify each element, marking them as "main" (main content) or "other" (auxiliary content)parse_result): Parses the classification results returned by LLMextract_main_html): Extracts main content from original HTML based on classification resultsMinerUHTMLConfig supports the following configurations:use_fall_back: Fallback type, optional 'trafilatura' or 'bypass'early_load: Whether to load the model early (default True)prompt_version: Prompt version, optional 'v2', 'compact'. The MinerUHTML interface and MinerUHTML_Transformers interface can use 'compact', the MinerUHTML_OpenAI interface can use 'v2''compact': Used for local model inference, it returns more concise results (only keeping the key and value in the JSON dictionary). It is recommended to use the 'compact' model for faster inference speed.'v2': Used for OpenAI API inference, it is the result after prompt optimization.MinerUHTMLGeneric:1from mineru_html import MinerUHTMLGeneric, MinerUHTMLConfig
2from mineru_html.inference.factory import create_vllm_backend, create_openai_backend, create_transformers_backend
3
4# Create VLLM backend using factory function
5llm = create_vllm_backend(
6 model_path='path/to/model',
7 response_format='compact',
8 max_context_window=32 * 1024,
9 model_init_kwargs={'tensor_parallel_size': 1}
10)
11
12# Create Transformers backend using factory function
13llm = create_transformers_backend(
14 model_path='path/to/model',
15 max_context_window=32 * 1024,
16 model_init_kwargs={
17 'device_map': 'auto',
18 'dtype': 'auto',
19 },
20 model_gen_kwargs={
21 'max_new_tokens': 8192,
22 }
23)
24
25# Create OpenAI backend using factory function
26llm = create_openai_backend(
27 base_url='https://api.openai.com/v1',
28 sk='your-api-key',
29 model='gpt-5',
30 max_context_window=128 * 1000
31)
32
33# Use the created backend
34config = MinerUHTMLConfig()
35extractor = MinerUHTMLGeneric(llm=llm, config=config)1from mineru_html.exceptions import MinerUHTMLError
2
3try:
4 result = extractor.process(html_content)
5except MinerUHTMLError as e:
6 print(f"Processing failed: {e}")
7 print(f"Case ID: {e.case_id}")MinerUHTML): Suitable for local deployment, requires GPU, best performanceMinerUHTML_Transformers): Suitable for local deployment, supports CPU/GPU, high flexibilityMinerUHTML_OpenAI): Suitable for cloud services, no local model required, simple to usepytest tests/