markdrop
1.0.0
一个用于在提取图像和表格时将PDF(或PDF URL)转换为降标的Python软件包。 Markdrop使得在保留图像和表格时可以轻松将PDF文档转换为降价格式。
pip install markdrop https://pypi.org/project/markdrop
from markdrop import extract_images , make_markdown , extract_tables_from_pdf
source_pdf = 'url/or/path/to/pdf/file' # Replace with your local PDF file path or a URL
output_dir = 'data/output' # Replace it with desired output directory's path
make_markdown ( source_pdf , output_dir )
extract_images ( source_pdf , output_dir , verbose = True )
extract_tables_from_pdf ( source_pdf , output_dir = output_dir ) from markdrop import setup_keys
### API Key Setup
### If using 'openai' or 'gemini' as llm_client in the generate_descriptions function, you need to set up the API keys first.
setup_keys () from markdrop import generate_descriptions
### Image Descriptions Generation
prompt = "Give textual highly detailed descriptions from this image ONLY, nothing else." # Replace it with your desired prompt
input_path = 'path/to/img_file/or/dir' # Replace it with the path to the images dir or image file
output_dir = 'data/output' # Replace it with the desired output directory's path
llm_clients = [ 'gemini' , 'llama-vision' ] # Replace it with the desired models from ['qwen', 'gemini', 'openai', 'llama-vision', 'molmo', 'pixtral'] only
generate_descriptions ( input_path = input_path , output_dir = output_dir , prompt = prompt , llm_client = llm_clients )将PDF或其URL转换为Markdown格式。
参数:
source (str):输入PDF或URL的路径output_dir (str):输出目录路径verbose (布尔):启用详细的记录从PDF或其URL提取图像,同时保持质量。
参数:
source (str):输入PDF或URL的路径output_dir (str):输出目录路径verbose (布尔):启用详细的记录检测和提取表图像。
参数:
pdf_path (str):输入路径PDF或URLstart_page (int,可选):启动页码end_page (int,可选):结尾页编号threshold (浮点,可选):检测置信度阈值output_dir (str):输出目录路径基于给定的提示和llm_client在CSV中生成图像的描述
支持的
llm clients为['qwen','gemini','Openai','Llama-vision','Molmo','pixtral']
参数:
input_path (str):输入PDF或URL的路径output_dir (str):输出目录路径prompt (str):提示与图像一起发送到模型llm_client (列表):列表包含LLM客户端的最低模型通过本地文件或URL分析PDF中不同类型的图像参考
参数:
source (str):本地PDF路径或url到PDFoutput_dir (str):临时文件目录verbose (布尔):打印详细信息我们欢迎捐款!有关详细信息,请参阅我们的贡献指南。
git clone https://github.com/shoryasethia/markdrop.git
cd markdrop python -m venv venv
source venv/bin/activate # On Windows: venvScriptsactivate pip install -r requirements.txt markdrop/
├── LICENSE
├── README.md
├── CONTRIBUTING.md
├── CHANGELOG.md
├── requirements.txt
├── setup.py
└── markdrop/
├── models/
| ├── .env
| ├── img_descriptions.py
| ├── logger.py
| ├── model_loader.py
| ├── responder.py
| └── setup_keys.py
├── __init__.py
├── main.py
├── utils.py
├── helper.py
└── ignore_warnings.py 该项目是根据MIT许可证获得许可的 - 有关详细信息,请参见许可证文件。
有关版本历史记录,请参见ChangElog.md。
请注意,该项目遵循我们的行为准则。