Image-Text-to-Text
Transformers
Safetensors
multilingual
hunyuan_vl
text-generation
ocr
hunyuan
vision-language
image-to-text
1B
end-to-end
conversational
Eval Results
Instructions to use tencent/HunyuanOCR with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tencent/HunyuanOCR with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="tencent/HunyuanOCR") 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)# Load model directly from transformers import AutoModelForSeq2SeqLM model = AutoModelForSeq2SeqLM.from_pretrained("tencent/HunyuanOCR", dtype="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use tencent/HunyuanOCR with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tencent/HunyuanOCR" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tencent/HunyuanOCR", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/tencent/HunyuanOCR
- SGLang
How to use tencent/HunyuanOCR with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "tencent/HunyuanOCR" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tencent/HunyuanOCR", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "tencent/HunyuanOCR" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tencent/HunyuanOCR", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use tencent/HunyuanOCR with Docker Model Runner:
docker model run hf.co/tencent/HunyuanOCR
Update README
#11
by EthannW - opened
README.md
CHANGED
|
@@ -70,16 +70,13 @@ processor = AutoProcessor.from_pretrained(model_name_or_path, use_fast=False)
|
|
| 70 |
img_path = "path/to/your/image.jpg"
|
| 71 |
image_inputs = Image.open(img_path)
|
| 72 |
messages1 = [
|
|
|
|
| 73 |
{
|
| 74 |
"role": "user",
|
| 75 |
"content": [
|
| 76 |
{"type": "image", "image": img_path},
|
| 77 |
{"type": "text", "text": (
|
| 78 |
-
"
|
| 79 |
-
"and represent it in markdown format, ignoring headers and footers. "
|
| 80 |
-
"Tables should be expressed in HTML format, formulas in the document "
|
| 81 |
-
"should be represented using LaTeX format, and the parsing should be "
|
| 82 |
-
"organized according to the reading order."
|
| 83 |
)},
|
| 84 |
],
|
| 85 |
}
|
|
@@ -183,9 +180,10 @@ sampling_params = SamplingParams(temperature=0, max_tokens=16384)
|
|
| 183 |
img_path = "/path/to/image.jpg"
|
| 184 |
img = Image.open(img_path)
|
| 185 |
messages = [
|
|
|
|
| 186 |
{"role": "user", "content": [
|
| 187 |
{"type": "image", "image": img_path},
|
| 188 |
-
{"type": "text", "text": "
|
| 189 |
]}
|
| 190 |
]
|
| 191 |
prompt = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|
|
|
|
| 70 |
img_path = "path/to/your/image.jpg"
|
| 71 |
image_inputs = Image.open(img_path)
|
| 72 |
messages1 = [
|
| 73 |
+
{"role": "system", "content": ""},
|
| 74 |
{
|
| 75 |
"role": "user",
|
| 76 |
"content": [
|
| 77 |
{"type": "image", "image": img_path},
|
| 78 |
{"type": "text", "text": (
|
| 79 |
+
"检测并识别图片中的文字,将文本坐标格式化输出。"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
)},
|
| 81 |
],
|
| 82 |
}
|
|
|
|
| 180 |
img_path = "/path/to/image.jpg"
|
| 181 |
img = Image.open(img_path)
|
| 182 |
messages = [
|
| 183 |
+
{"role": "system", "content": ""},
|
| 184 |
{"role": "user", "content": [
|
| 185 |
{"type": "image", "image": img_path},
|
| 186 |
+
{"type": "text", "text": "检测并识别图片中的文字,将文本坐标格式化输出。"}
|
| 187 |
]}
|
| 188 |
]
|
| 189 |
prompt = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
|