YAML Metadata Warning:empty or missing yaml metadata in repo card
Check out the documentation for more information.
MinerU-HTML
MinerU-HTML is an intelligent HTML main content extraction tool based on Large Language Models (LLM). It can accurately identify and extract main content from complex web page HTML, automatically filtering out auxiliary elements such as navigation bars, advertisements, and metadata.
β¨ Features
- π― LLM-Powered Extraction: Uses state-of-the-art language models to intelligently identify main content
- β‘ Compact Format: Now use compact format for the model instead of the original JSON format for faster inference speed
- π Complete Processing Pipeline: Includes HTML simplification, prompt construction, LLM inference, result parsing, main content extraction, and other complete processes
- π Multiple Inference Backend Support: Supports three inference backends: VLLM, Transformers, and OpenAI API
- π‘οΈ Fault Tolerance: Supports fallback mechanism (trafilatura or bypass) to ensure content extraction even when processing fails
- π Modular Design: Clear architecture design, easy to extend and customize
- π§ͺ Complete Testing: Includes comprehensive unit tests and integration tests
π Directory Structure
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)
π Quick Start
Installation
Basic Installation (Core Dependencies Only)
pip install .
# Or development mode
pip install -e .
Install Specific Backend Dependencies
Depending on your use case, you can choose to install different backend dependencies:
# Install OpenAI backend dependencies
pip install .[openai]
# Install VLLM backend dependencies
pip install .[vllm]
# Install all dependencies
pip install .[all]
Basic Usage
Using VLLM Backend
from mineru_html import MinerUHTML, MinerUHTMLConfig
# Create configuration
config = MinerUHTMLConfig(
use_fall_back='trafilatura', # or 'bypass'
prompt_version='compact', # recommend using compact
early_load=True
)
# Initialize MinerUHTML (using local model)
extractor = MinerUHTML(
model_path='path/to/your/model', # The model used must correspond to the prompt_version in MinerUHTMLConfig
config=config
)
# Process single HTML
html_content = '<html>...</html>'
result = extractor.process(html_content)
print(result[0].main_html)
# Process multiple HTML
html_list = ['<html>...</html>', '<html>...</html>']
results = extractor.process(html_list)
for result in results:
print(result.main_html)
print(result.case_id)
Using OpenAI API Backend
from mineru_html import MinerUHTML_OpenAI, MinerUHTMLConfig
# Create configuration
config = MinerUHTMLConfig(
use_fall_back='trafilatura',
prompt_version='v2', # Recommend using v2
early_load=True
)
# Initialize MinerUHTML_OpenAI
extractor = MinerUHTML_OpenAI(
base_url='https://api.openai.com/v1',
sk='your-api-key',
model='gpt-5',
config=config,
retry_times=3
)
# Process HTML
html_content = '<html>...</html>'
result = extractor.process(html_content)
print(result[0].main_html)
Using Transformers Backend
from mineru_html import MinerUHTML_Transformers, MinerUHTMLConfig
# Create configuration
config = MinerUHTMLConfig(
use_fall_back='trafilatura',
prompt_version='v2',
early_load=True
)
# Initialize MinerUHTML_Transformers
extractor = MinerUHTML_Transformers(
model_path='path/to/your/model', # The model used must correspond to the prompt_version in MinerUHTMLConfig
config=config,
model_init_kwargs={
'device_map': 'auto',
'dtype': 'auto',
},
model_gen_kwargs={
'max_new_tokens': 8192,
}
)
# Process HTML
html_content = '<html>...</html>'
result = extractor.process(html_content)
print(result[0].main_html)
π Core Concepts
Processing Pipeline
The MinerU-HTML processing pipeline includes the following steps:
- HTML Simplification (
simplify_html): Simplifies raw HTML into a structured format, assigning a unique_item_idattribute to each element - Prompt Construction (
build_prompt): Constructs LLM prompts based on simplified HTML to guide the model in content classification - LLM Inference (
inference): Uses LLM to classify each element, marking them as "main" (main content) or "other" (auxiliary content) - Result Parsing (
parse_result): Parses the classification results returned by LLM - Main Content Extraction (
extract_main_html): Extracts main content from original HTML based on classification results - Fallback Processing: If the above process fails, uses fallback mechanism (trafilatura or bypass) for content extraction
Configuration Options
MinerUHTMLConfig supports the following configurations:
use_fall_back: Fallback type, optional'trafilatura'or'bypass'early_load: Whether to load the model early (defaultTrue)prompt_version: Prompt version, optional'v2','compact'. The MinerUHTML interface and MinerUHTML_Transformers interface can use'compact', the MinerUHTML_OpenAI interface can use'v2'
Usage instructions for different prompt_version:
'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.
π§ Advanced Usage
Using Factory Functions to Create Backends
You can also directly use factory functions to create backends and then pass them to MinerUHTMLGeneric:
from mineru_html import MinerUHTMLGeneric, MinerUHTMLConfig
from mineru_html.inference.factory import create_vllm_backend, create_openai_backend, create_transformers_backend
# Create VLLM backend using factory function
llm = create_vllm_backend(
model_path='path/to/model',
response_format='compact',
max_context_window=32 * 1024,
model_init_kwargs={'tensor_parallel_size': 1}
)
# Create Transformers backend using factory function
llm = create_transformers_backend(
model_path='path/to/model',
max_context_window=32 * 1024,
model_init_kwargs={
'device_map': 'auto',
'dtype': 'auto',
},
model_gen_kwargs={
'max_new_tokens': 8192,
}
)
# Create OpenAI backend using factory function
llm = create_openai_backend(
base_url='https://api.openai.com/v1',
sk='your-api-key',
model='gpt-5',
max_context_window=128 * 1000
)
# Use the created backend
config = MinerUHTMLConfig()
extractor = MinerUHTMLGeneric(llm=llm, config=config)
Error Handling
from mineru_html.exceptions import MinerUHTMLError
try:
result = extractor.process(html_content)
except MinerUHTMLError as e:
print(f"Processing failed: {e}")
print(f"Case ID: {e.case_id}")
Backend Selection Recommendations
- VLLM Backend (
MinerUHTML): Suitable for local deployment, requires GPU, best performance - Transformers Backend (
MinerUHTML_Transformers): Suitable for local deployment, supports CPU/GPU, high flexibility - OpenAI API Backend (
MinerUHTML_OpenAI): Suitable for cloud services, no local model required, simple to use
π§ͺ Testing
Run unit tests and integration tests:
pytest tests/
- Downloads last month
- 5
Inference Providers NEW
This model isn't deployed by any Inference Provider. π Ask for provider support