Instructions to use anyforge/anyparse-models-hub with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use anyforge/anyparse-models-hub with Transformers:
# Use a pipeline as a high-level helper # Warning: Pipeline type "image-to-text" is no longer supported in transformers v5. # You must load the model directly (see below) or downgrade to v4.x with: # 'pip install "transformers<5.0.0' from transformers import pipeline pipe = pipeline("image-to-text", model="anyforge/anyparse-models-hub")# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("anyforge/anyparse-models-hub", device_map="auto") - Notebooks
- Google Colab
- Kaggle
File size: 5,154 Bytes
7b024fe 898518b 7b024fe 3a0be69 3adb3a5 e9e409e 8895cf4 e9e409e 8895cf4 f0edc7c e9e409e caba267 e9e409e 898518b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | ---
license: apache-2.0
pipeline_tag: image-to-text
library_name: transformers
tags:
- ocr
- pdf
- markdown
- office
---
## anyparse models hub
**AnyParse** is a powerful multimodal document parsing and understanding engine designed to seamlessly convert complex files into structured Markdown and JSON formats. Whether it's basic text processing, professional document conversion, or advanced Vision-Language Models (VLM) and OCR recognition, AnyParse provides a comprehensive, one-stop solution.
### Core Capabilities
- **Multimodal Document Understanding:** Supports cross-modal parsing of images and documents. By combining OCR and VLM technologies, it accurately extracts unstructured data.
- **Comprehensive Format Coverage:** Easily parses office documents, web pages, spreadsheets, e-books, and emails with a single tool.
- **Structured Output:** Transforms complex files into standardized Markdown and JSON, streamlining downstream data processing and Large Language Model (LLM) applications.
### Key Features
- **Documents & Layouts:** PDF, DOCX, PPTX, XLSX, EPUB, IPYNB
- **Text & Markup:** TXT, MD, RST, HTML/XHTML/HTM/SHTML
- **Spreadsheets & Data:** CSV, TSV
- **Images & Multimedia:** PNG, JPEG/JPG
- **Others:** EML (Emails)
- **Built-in CLI, FastAPI**
- **Supports running in a pure CPU environment, and also supports GPU**
- Output text in human reading order, suitable for single-column, multi-column and complex layouts
- Retain the original document structure, including titles, paragraphs, lists, etc.
- Extract images, image descriptions, tables, table titles and footnotes
- Automatically identify and convert formulas in documents to LaTeX format
- Automatically identify and convert tables in documents to HTML format
### resources
- **repo: [AnyParse](https://github.com/anyforge/anyparse)**
- **docs: [AnyParse docs](https://anyforge.github.io/anyparse)**
- **pypi: [anyparse-python](https://pypi.org/project/anyparse-python/)**
- **[ModelScope Skills](https://www.modelscope.cn/skills/anyforge/anyparse-skill)**
- **[SkillHub](https://skillhub.cn/skills/anyparse-skill)**
- **[ClawHub](https://clawhub.ai/anyforge/skills/anyparse-skill)**
```bash
pip install anyparse-python
```
please download `config/config.yaml` from [AnyParse](https://github.com/anyforge/anyparse) into your project directory.
### Download Models
```bash
# use modelscope (default)
export ANYPARSE_MODEL_MIRROR="modelscope"
# use huggingface
export ANYPARSE_MODEL_MIRROR="huggingface"
# download models
anyparse-cli download --config config/config.yaml --model
```
### Models Hub
- [AnyParse Models Hub ModelScope](https://www.modelscope.cn/models/anyforge/anyparse-models-hub)
- [AnyParse Models Hub HuggingFace](https://huggingface.co/anyforge/anyparse-models-hub)
### Python
```python
# Sync
from anyparse import AnyParser
model = AnyParser(config="config/config.yaml")
res = model.invoke(file = "/path/to/your_file")
# or Async
from anyparse import AsyncAnyParser
model = AsyncAnyParser(config="config/config.yaml")
res = await model.ainvoke(file = "/path/to/your_file")
```
### CLI
```bash
# help
anyparse-cli --help
# parse file
anyparse-cli parse --config config/config.yaml --file /path/to/your_file
# start api server
anyparse-cli api --config config/config.yaml
# see allowed file types
anyparse-cli allow --config config/config.yaml
# see commands help
anyparse-cli [COMMAND] --help
```
### API
- start api server
```bash
# start fastapi server and openai proxy
## use restful api or openai client call
anyparse-cli api --config config/config.yaml --host 0.0.0.0 --port 18007 --seckey 'your_custom_secret_key'
```
- call api
```python
# openai
from openai import OpenAI
client = OpenAI(
base_url = "http://localhost:18007/anyparse/openai/v1",
api_key = "your_custom_secret_key",
)
## get model id and allowed file types
print(client.models.list())
## parse file
import base64
with open("1.pdf", "r", encoding="utf-8") as f:
text_content = f.read()
encoded_bytes = base64.b64encode(text_content.encode('utf-8'))
base64_str = encoded_bytes.decode('utf-8')
response = client.chat.completions.create(
model="anyparse",
messages=[
{
"role": "user",
"content": [
{
"type": "file",
"file": {
"file_data": f"data:application/pdf;base64,{base64_str}"
}
}
]
}
], # data:application/pdf;base64 prefix follow: client.models.list().data[0].allow_mimetypes
# extra_body={
# "runtimes_args": {
# "use_doc_layout": True
# }
# }
)
print(response.choices[0].message.content)
# or restful
import requests as rq
headers = {
"Authorization": "Bearer your_custom_secret_key"
}
url = "http://localhost:18007/anyparse/invoke/v1"
args = {
"use_doc_cls": False,
"use_doc_rectifier": False,
"use_doc_layout": True
}
file = '/path/to/your_file'
files = {
'file': open(file,'rb')
}
res = rq.post(url, files = files, data = args, headers = headers)
print(res.json())
``` |