Spaces:
Running
on
Zero
title: parser2md - PDF & HTML parser to markdown
emoji: π
colorFrom: yellow
colorTo: purple
sdk: gradio
sdk_version: 5.44.1
python_version: 3.12
command: python main.py
app_file: main.py
hf_oauth: true
oauth_scopes:
- read-access
hf_oauth_scopes:
- inference-api
license: mit
pinned: true
short_description: PDF & HTML parser to markdown
models:
- meta-llama/Llama-4-Maverick-17B-128E-Instruct
- openai/gpt-oss-120b, openai/gpt-oss-20b
- vikp/surya_det3
- vikp/surya_rec2
- vikp/surya_tablerec
- datalab-to/surya_layout
- datalab-to/surya_tablerec
- datalab-to/texify
- datalab-to/ocr_error_detection
- datalab-to/inline_math_det0
- datalab-to/line_detector0
- xiaoyao9184/surya_text_detection
- xiaoyao9184/surya_text_recognition
- xiaoyao9184/surya_table_recognition
- xiaoyao9184/surya_texify
- xiaoyao9184/surya_layout
- xiaoyao9184/surya_ocr_error_detection
- xiaoyao9184/surya_inline_math_detection]
tags:
- markdown
- PDF
- parser
- converter
- extractor
owner: research-semmyk
version: 0.1.0
readme: README.md
requires-python: '>=3.12'
parserPDF
A Gradio-based web application for converting PDF, HTML and Word documents to Markdown format. Powered by the Marker library (a pipeline of deep learning models for document parsing) and optional LLM integration for enhanced processing. Supports batch processing of files and directories via an intuitive UI.
Features
- PDF to Markdown: Extract text, tables, and images from PDFs, HTMLs and Word documents using Marker.
- HTML to Markdown: Convert HTML files to clean Markdown. #Deprecated
- Batch Processing: Upload multiple files or entire directories.
- LLM Integration: Optional use of Hugging Face or OpenAI models for advanced conversion (e.g., via Llama or GPT models).
- Customizable Settings: Adjust model parameters, output formats (Markdown/HTML), page ranges, and more via the UI.
- Output Management: Generated Markdown files saved to a configurable output directory, with logs and download links.
Project Structure
parserpdf/
βββ README.md # Project documentation
βββ requirements.txt # Python dependencies
βββ main.py # Entry point β launches the Gradio UI
βββ pyproject.toml # Project configuration
βββ .env # Environment variables (e.g., API tokens)
βββ .gitignore # Git ignore rules
βββ converters/ # Conversion logic
β βββ __init__.py
β βββ extraction_converter.py # Document extraction utilities
β βββ pdf_to_md.py # Marker-based PDF, HTML, Word β Markdown
β βββ html_to_md.py # HTML β Markdown #Deprecated
β βββ md_to_pdf.py # Markdown β PDF (pending full implementation)
βββ file_handler/ # File handling utilities
β βββ __init__.py
β βββ file_utils.py # Helpers for files, directories, and paths
βββ llm/ # LLM client integrations
β βββ __init__.py
β βββ hf_client.py # Hugging Face client wrapper ##PutOnHold
β βββ openai_client.py # Marker OpenAI client ##NotFullyImplemented
β βββ llm_login.py # Authentication handlers
β βββ provider_validator.py # Provider validation
βββ ui/ # Gradio UI components
β βββ __init__.py
β βββ gradio_ui.py # UI layout, event handlers and coordination
βββ utils/ # Utility modules
β βββ __init__.py
β βββ config.py # Configuration constants
β βββ config.ini # config file for settings
β βββ logger.py # Logging wrapper
β βββ lib_loader.py # loads weasyprint lib dependencies to environ
β βββ get_config.py # helper for getting configurations
β βββ get_arg_name.py # helper for getting argument names
β βββ utils.py # General utilities and helpers
βββ data/ # Sample data and outputs (gitignored)
β βββ output_dir/ # Output directory
β βββ pdf/ # Sample PDFs
βββ logs/ # Log files (gitignored)
βββ tests/ # Unit tests ##ToBeUpdated
β βββ tests_converter.py # tests for converters
βββ scrapyard/ # Development scraps
[Projected]
βββ transformers/
β βββ __init__.py
β βββ marker.py # Marker class
β βββ marker_utils.py # helpers for Marker class
Installation
Clone the repository:
git clone <repo-url> cd parserpdfCreate a virtual environment and install dependencies:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txtSet up environment variables (optional for LLM features):
- Create a
.envfile with your API tokens, e.g.:HF_TOKEN=hf_xxx OPENAI_API_KEY=sk-xxx - HuggingFace login (oauth) integrated with Gradio:
- Create a
Install Marker (if not in requirements.txt):
pip install marker-pdf[full]
Usage
Run the application:
python main.pyOpen the provided local URL (e.g., http://127.0.0.1:7860) in your browser.
In the UI:
- Upload PDF/HTML/Word files or directories via the "PDF, HTML & Word β Markdown" tab.
- Configure LLM/Marker settings in the accordions (e.g., select provider, model, tokens).
- Click "Process All Uploaded Files" to convert.
- View logs, JSON output, and download generated Markdown files.
Example Workflow
- Upload a PDF directory.
- Set model to
meta-llama/Llama-4-Maverick-17B-128E-Instruct(Hugging Face). - Enable LLM if needed, set page range (e.g., "1-10").
- Process: Outputs Markdown files with extracted text/images to
output_dir.
Configuration
- Edit
utils/config.iniorutils/config.pyfor defaults (e.g., model ID, output dir). - On windows, set weasyprint's GTK path: e.g. "C:\Dat\dev\gtk3-runtime\bin" or "C:\msys64\mingw64\bin"
- UI overrides: Adjust sliders for max tokens, temperature, workers, etc.
LLM Providers
- Hugging Face: Supports inference providers like Fireworks AI, Together AI.
- OpenAI: Compatible via router (default: https://router.huggingface.co/v1).
- Login via UI or CLI:
huggingface-cli login.
Output
- Markdown files saved to
output_dir(default:./output_dir). - Images extracted as JPEGs alongside Markdown.
- Logs in
logs/and UI textbox.
Limitations & TODO
- Markdown β PDF is pending full implementation.
- HTML tab is deprecated; use main tab for mixed uploads.
- Large files/directories may require increased
max_workersand higher processing power. - No JSON/chunks output yet (flagged for future).
Contributing
Fork the repo, create a branch, and submit a PR.
- GitHub
- HuggingFace Space Community
Ensure tests pass: - verify the application's functionality. ##TardyOutdated
pytest tests/
Test Structure
- tests/test_converters.py: Tests PDF/HTML/Markdown converters, including init, conversion, batch processing, and error handling.
- tests/test_file_handler.py: Tests file collection utilities (PDF/HTML/MD paths), data processing, and output directory creation.
- tests/test_utils.py: Tests logging setup, config loading, utility functions like is_dict/is_list_of_dicts, and configuration access.
- tests/test_llm.py: Tests LLM login, provider validation, Hugging Face/OpenAI client initialization, and API interactions.
- tests/test_main_ui.py: Tests main application logic, UI building, batch conversion, file accumulation, and ProcessPoolExecutor integration.
License
MIT License. See LICENSE for details.
Acknowledgments
- Built with Gradio for the UI.
- PDF parsing via Marker.
- LLM integrations using Hugging Face Transformers and OpenAI APIs.
- HuggingFace Spaces Configuration Reference HF Spaces Configuration Reference
- IBM Research: HF Spaces Guide