Views
No views yet
<figure> – for figures, charts, and diagrams<figure>
A bar chart comparing domestic and export revenue growth
between Q1 and Q2 2025.
</figure><page_number> – for preserving page number<page_number>1</page_number>


1prompt = """Extract all text from the image.
2
3Instructions:
4- Only return the clean Markdown.
5- Do not include any explanation or extra text.
6- You must include all information on the page.
7
8Formatting Rules:
9- Tables: Render tables using <table>...</table> in clean HTML format.
10- Equations: Render equations using LaTeX syntax with inline ($...$) and block ($$...$$).
11- Images/Charts/Diagrams: Wrap any clearly defined visual areas (e.g. charts, diagrams, pictures) in:
12
13<figure>
14Describe the image's main elements (people, objects, text), note any contextual clues (place, event, culture), mention visible text and its meaning, provide deeper analysis when relevant (especially for financial charts, graphs, or documents), comment on style or architecture if relevant, then give a concise overall summary. Describe in Thai.
15</figure>
16
17- Page Numbers: Wrap page numbers in <page_number>...</page_number> (e.g., <page_number>14</page_number>).
18- Checkboxes: Use ☐ for unchecked and ☑ for checked boxes."""pip install typhoon-ocr -U1from typhoon_ocr import ocr_document
2
3# please set env TYPHOON_OCR_API_KEY or OPENAI_API_KEY to use this function
4markdown = ocr_document("test.png", model = "typhoon-ocr", figure_language = "Thai", task_type = "v1.5")
5print(markdown)1pip install vllm
2vllm serve scb10x/typhoon-ocr1.5-2b --max-model-len 49152 --served-model-name typhoon-ocr-1-5 # OpenAI Compatible at http://localhost:8000 (or other port)
3# then you can supply base_url in to ocr_document1from typhoon_ocr import ocr_document
2markdown = ocr_document('image.png', model = "typhoon-ocr" , figure_language = "Thai" , task_type="v1.5", base_url='http://localhost:8000/v1', api_key='no-key')
3print(markdown)1from transformers import AutoModelForImageTextToText, AutoProcessor
2from PIL import Image
3
4def resize_if_needed(img, max_size):
5 width, height = img.size
6 # Only resize if one dimension exceeds max_size
7 if width > 300 or height > 300:
8 if width >= height:
9 scale = max_size / float(width)
10 new_size = (max_size, int(height * scale))
11 else:
12 scale = max_size / float(height)
13 new_size = (int(width * scale), max_size)
14
15 img = img.resize(new_size, Image.Resampling.LANCZOS)
16 print(f"{width, height}==> {img.size}")
17 return img
18 else:
19 return img
20
21
22model = AutoModelForImageTextToText.from_pretrained(
23 "scb10x/typhoon-ocr1.5-2b", dtype="auto", device_map="auto"
24)
25processor = AutoProcessor.from_pretrained("scb10x/typhoon-ocr1.5-2b")
26
27img = Image.open("image.png")
28
29
30#This is important because the model is trained with a fixed image dimension of 1800 px
31img = resize_if_needed(img, 1800)
32
33messages = [
34 {
35 "role": "user",
36 "content": [
37 {
38 "type": "image",
39 "image": img,
40 },
41 {
42 "type": "text",
43 "text": prompt
44 }
45 ],
46 }
47 ]
48
49# Preparation for inference
50inputs = processor.apply_chat_template(
51 messages,
52 tokenize=True,
53 add_generation_prompt=True,
54 return_dict=True,
55 return_tensors="pt"
56)
57inputs = inputs.to(model.device)
58
59# Inference: Generation of the output
60generated_ids = model.generate(**inputs, max_new_tokens=10000)
61generated_ids_trimmed = [
62 out_ids[len(in_ids) :] for in_ids, out_ids in zip(inputs.input_ids, generated_ids)
63]
64output_text = processor.batch_decode(
65 generated_ids_trimmed, skip_special_tokens=True, clean_up_tokenization_spaces=False
66)
67print(output_text[0])1pip install vllm
2vllm serve scb10x/typhoon-ocr1.5-2b --max-model-len 49152 --served-model-name typhoon-ocr-1-5 # OpenAI Compatible at http://localhost:8000
3# then you can supply base_url in to ocr_document1from typhoon_ocr import ocr_document
2markdown = ocr_document('image.png', model = "typhoon-ocr" , figure_language = "Thai", task_type="v1.5", base_url='http://localhost:8000/v1', api_key='no-key')
3print(markdown)@misc{typhoon2,
title={Typhoon 2: A Family of Open Text and Multimodal Thai Large Language Models},
author={Kunat Pipatanakul and Potsawee Manakul and Natapong Nitarach and Warit Sirichotedumrong and Surapon Nonesung and Teetouch Jaknamon and Parinthapat Pengpun and Pittawat Taveekitworachai and Adisai Na-Thalang and Sittipong Sripaisarnmongkol and Krisanapong Jirayoot and Kasima Tharnpipitchai},
year={2024},
eprint={2412.13702},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2412.13702},
}
@misc{nonesung2025thaiocrbenchtaskdiversebenchmarkvisionlanguage,
title={ThaiOCRBench: A Task-Diverse Benchmark for Vision-Language Understanding in Thai},
author={Surapon Nonesung and Teetouch Jaknamon and Sirinya Chaiophat and Natapong Nitarach and Chanakan Wittayasakpan and Warit Sirichotedumrong and Adisai Na-Thalang and Kunat Pipatanakul},
year={2025},
eprint={2511.04479},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2511.04479},
}