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
Update README.md
Browse files
README.md
CHANGED
|
@@ -4,4 +4,156 @@ license: apache-2.0
|
|
| 4 |
|
| 5 |
## anyparse models hub
|
| 6 |
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
## anyparse models hub
|
| 6 |
|
| 7 |
+
**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.
|
| 8 |
+
|
| 9 |
+
### Core Capabilities
|
| 10 |
+
|
| 11 |
+
- **Multimodal Document Understanding:** Supports cross-modal parsing of images and documents. By combining OCR and VLM technologies, it accurately extracts unstructured data.
|
| 12 |
+
- **Comprehensive Format Coverage:** Easily parses office documents, web pages, spreadsheets, e-books, and emails with a single tool.
|
| 13 |
+
- **Structured Output:** Transforms complex files into standardized Markdown and JSON, streamlining downstream data processing and Large Language Model (LLM) applications.
|
| 14 |
+
|
| 15 |
+
### Key Features
|
| 16 |
+
|
| 17 |
+
- **Documents & Layouts:** PDF, DOCX, PPTX, XLSX, EPUB, IPYNB
|
| 18 |
+
- **Text & Markup:** TXT, MD, RST, HTML/XHTML/HTM/SHTML
|
| 19 |
+
- **Spreadsheets & Data:** CSV, TSV
|
| 20 |
+
- **Images & Multimedia:** PNG, JPEG/JPG
|
| 21 |
+
- **Others:** EML (Emails)
|
| 22 |
+
- **Built-in CLI, FastAPI**
|
| 23 |
+
- **Supports running in a pure CPU environment, and also supports GPU**
|
| 24 |
+
- Output text in human reading order, suitable for single-column, multi-column and complex layouts
|
| 25 |
+
- Retain the original document structure, including titles, paragraphs, lists, etc.
|
| 26 |
+
- Extract images, image descriptions, tables, table titles and footnotes
|
| 27 |
+
- Automatically identify and convert formulas in documents to LaTeX format
|
| 28 |
+
- Automatically identify and convert tables in documents to HTML format
|
| 29 |
+
|
| 30 |
+
- **repo: [AnyParse](https://github.com/anyforge/anyparse)**
|
| 31 |
+
- **docs: [AnyParse docs](https://anyforge.github.io/anyparse)**
|
| 32 |
+
|
| 33 |
+
```bash
|
| 34 |
+
pip install anyparse-python
|
| 35 |
+
```
|
| 36 |
+
|
| 37 |
+
### Python
|
| 38 |
+
|
| 39 |
+
```python
|
| 40 |
+
# Sync
|
| 41 |
+
from anyparse import AnyParser
|
| 42 |
+
|
| 43 |
+
model = AnyParser(config="config/config.yaml")
|
| 44 |
+
res = model.invoke(file = "/path/to/your_file")
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
# or Async
|
| 49 |
+
from anyparse import AsyncAnyParser
|
| 50 |
+
|
| 51 |
+
model = AsyncAnyParser(config="config/config.yaml")
|
| 52 |
+
res = await model.ainvoke(file = "/path/to/your_file")
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
### CLI
|
| 56 |
+
|
| 57 |
+
```bash
|
| 58 |
+
# help
|
| 59 |
+
|
| 60 |
+
anyparse-cli --help
|
| 61 |
+
|
| 62 |
+
# parse file
|
| 63 |
+
anyparse-cli parse --config config/config.yaml --file /path/to/your_file
|
| 64 |
+
|
| 65 |
+
# start api server
|
| 66 |
+
anyparse-cli api --config config/config.yaml
|
| 67 |
+
|
| 68 |
+
# see allowed file types
|
| 69 |
+
anyparse-cli allow --config config/config.yaml
|
| 70 |
+
|
| 71 |
+
# see commands help
|
| 72 |
+
anyparse-cli [COMMAND] --help
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
### API
|
| 76 |
+
|
| 77 |
+
- start api server
|
| 78 |
+
|
| 79 |
+
```bash
|
| 80 |
+
# start fastapi server and openai proxy
|
| 81 |
+
## use restful api or openai client call
|
| 82 |
+
anyparse-cli api --config config/config.yaml --host 0.0.0.0 --port 18007 --seckey 'your_custom_secret_key'
|
| 83 |
+
```
|
| 84 |
+
|
| 85 |
+
- call api
|
| 86 |
+
|
| 87 |
+
```python
|
| 88 |
+
# openai
|
| 89 |
+
from openai import OpenAI
|
| 90 |
+
|
| 91 |
+
client = OpenAI(
|
| 92 |
+
base_url = "http://localhost:18007/anyparse/openai/v1",
|
| 93 |
+
api_key = "your_custom_secret_key",
|
| 94 |
+
)
|
| 95 |
+
## get model id and allowed file types
|
| 96 |
+
print(client.models.list())
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
## parse file
|
| 101 |
+
import base64
|
| 102 |
+
|
| 103 |
+
with open("1.pdf", "r", encoding="utf-8") as f:
|
| 104 |
+
text_content = f.read()
|
| 105 |
+
|
| 106 |
+
encoded_bytes = base64.b64encode(text_content.encode('utf-8'))
|
| 107 |
+
base64_str = encoded_bytes.decode('utf-8')
|
| 108 |
+
|
| 109 |
+
response = client.chat.completions.create(
|
| 110 |
+
model="anyparse",
|
| 111 |
+
messages=[
|
| 112 |
+
{
|
| 113 |
+
"role": "user",
|
| 114 |
+
"content": [
|
| 115 |
+
{
|
| 116 |
+
"type": "file",
|
| 117 |
+
"file": {
|
| 118 |
+
"file_data": f"data:application/pdf;base64,{base64_str}"
|
| 119 |
+
}
|
| 120 |
+
}
|
| 121 |
+
]
|
| 122 |
+
}
|
| 123 |
+
], # data:application/pdf;base64 prefix follow: client.models.list().data[0].allow_mimetypes
|
| 124 |
+
# extra_body={
|
| 125 |
+
# "runtimes_args": {
|
| 126 |
+
# "use_doc_layout": True
|
| 127 |
+
# }
|
| 128 |
+
# }
|
| 129 |
+
)
|
| 130 |
+
|
| 131 |
+
print(response.choices[0].message.content)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
# or restful
|
| 136 |
+
import requests as rq
|
| 137 |
+
|
| 138 |
+
headers = {
|
| 139 |
+
"Authorization": "Bearer your_custom_secret_key"
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
url = "http://localhost:18007/anyparse/invoke/v1"
|
| 143 |
+
|
| 144 |
+
args = {
|
| 145 |
+
"use_doc_cls": False,
|
| 146 |
+
"use_doc_rectifier": False,
|
| 147 |
+
"use_doc_layout": True
|
| 148 |
+
}
|
| 149 |
+
|
| 150 |
+
file = '/path/to/your_file'
|
| 151 |
+
|
| 152 |
+
files = {
|
| 153 |
+
'file': open(file,'rb')
|
| 154 |
+
}
|
| 155 |
+
|
| 156 |
+
res = rq.post(url, files = files, data = args, headers = headers)
|
| 157 |
+
print(res.json())
|
| 158 |
+
|
| 159 |
+
```
|