Instructions to use zai-org/GLM-OCR with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use zai-org/GLM-OCR 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="zai-org/GLM-OCR") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForMultimodalLM tokenizer = AutoTokenizer.from_pretrained("zai-org/GLM-OCR") model = AutoModelForMultimodalLM.from_pretrained("zai-org/GLM-OCR", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- AMD Developer Cloud
move SDK
#23
by JaredforReal - opened
README.md
CHANGED
|
@@ -59,6 +59,10 @@ For speed, we compared different OCR methods under identical hardware and testin
|
|
| 59 |
|
| 60 |
## Usage
|
| 61 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
### vLLM
|
| 63 |
|
| 64 |
1. run
|
|
@@ -200,9 +204,6 @@ GLM-OCR currently supports two types of prompt scenarios:
|
|
| 200 |
|
| 201 |
⚠️ Note: When using information extraction, the output must strictly adhere to the defined JSON schema to ensure downstream processing compatibility.
|
| 202 |
|
| 203 |
-
## GLM-OCR SDK
|
| 204 |
-
|
| 205 |
-
We provide an easy-to-use SDK for using GLM-OCR more efficiently and conveniently. please check our [github](https://github.com/zai-org/GLM-OCR) to get more detail.
|
| 206 |
|
| 207 |
## Acknowledgement
|
| 208 |
|
|
|
|
| 59 |
|
| 60 |
## Usage
|
| 61 |
|
| 62 |
+
## GLM-OCR SDK
|
| 63 |
+
|
| 64 |
+
We provide an easy-to-use SDK for using GLM-OCR more efficiently and conveniently. please check our [github](https://github.com/zai-org/GLM-OCR) to get more detail.
|
| 65 |
+
|
| 66 |
### vLLM
|
| 67 |
|
| 68 |
1. run
|
|
|
|
| 204 |
|
| 205 |
⚠️ Note: When using information extraction, the output must strictly adhere to the defined JSON schema to ensure downstream processing compatibility.
|
| 206 |
|
|
|
|
|
|
|
|
|
|
| 207 |
|
| 208 |
## Acknowledgement
|
| 209 |
|