Image-Text-to-Text
Transformers
Safetensors
Vietnamese
English
qwen3_5
ocr
document-parsing
vietnamese
vllm
distillation
pruning
grounding
conversational
Instructions to use DuyTa/Peppercorn_Base with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use DuyTa/Peppercorn_Base with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="DuyTa/Peppercorn_Base") 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 AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("DuyTa/Peppercorn_Base") model = AutoModelForMultimodalLM.from_pretrained("DuyTa/Peppercorn_Base", 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 = processor.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(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use DuyTa/Peppercorn_Base with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "DuyTa/Peppercorn_Base" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "DuyTa/Peppercorn_Base", "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/DuyTa/Peppercorn_Base
- SGLang
How to use DuyTa/Peppercorn_Base 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 "DuyTa/Peppercorn_Base" \ --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": "DuyTa/Peppercorn_Base", "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 "DuyTa/Peppercorn_Base" \ --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": "DuyTa/Peppercorn_Base", "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 DuyTa/Peppercorn_Base with Docker Model Runner:
docker model run hf.co/DuyTa/Peppercorn_Base
Download examples/client.py from DuyTa/Peppercorn_Base: direct link, hf CLI and curl.
- Browser
- Download file 3.14 kB
-
https://huggingface.co/DuyTa/Peppercorn_Base/resolve/main/examples/client.py
- Command line
-
hf download hf://DuyTa/Peppercorn_Base/examples/client.py
-
curl -L -o client.py https://huggingface.co/DuyTa/Peppercorn_Base/resolve/main/examples/client.py
3.14 kB
| """Read page images through `serve.sh`, one request per page. | |
| python examples/client.py page1.png page2.jpg ... # Markdown (transcription mode) | |
| python examples/client.py --mode grounding page1.png # Markdown with block boxes | |
| python examples/client.py --url http://127.0.0.1:8000/v1 --out pages.jsonl --concurrency 64 *.png | |
| Pages are downscaled to a 2,048 px longest edge (the training and evaluation resolution; 1,540 px is | |
| faster and slightly less accurate). Greedy decoding, at most 4,096 output tokens. A page that starts to | |
| loop is trimmed after the first copy of the repeated span (loop_guard.scan), finish = "loop". | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import asyncio | |
| import base64 | |
| import io | |
| import json | |
| import os | |
| import sys | |
| from openai import AsyncOpenAI | |
| from PIL import Image | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| from loop_guard import scan # noqa: E402 | |
| def encode(path: str, edge: int) -> str: | |
| im = Image.open(path).convert("RGB") | |
| if max(im.size) > edge: | |
| im.thumbnail((edge, edge), Image.LANCZOS) | |
| buf = io.BytesIO() | |
| im.save(buf, format="PNG") | |
| return base64.b64encode(buf.getvalue()).decode() | |
| async def read(cli: AsyncOpenAI, path: str, mode: str, edge: int, sem: asyncio.Semaphore) -> dict: | |
| async with sem: | |
| b64 = await asyncio.to_thread(encode, path, edge) | |
| content = [{"type": "image_url", "image_url": {"url": f"data:image/png;base64,{b64}"}}] | |
| if mode == "grounding": | |
| content.append({"type": "text", "text": "grounding"}) | |
| resp = await cli.chat.completions.create(model="peppercorn", temperature=0, max_tokens=4096, | |
| messages=[{"role": "user", "content": content}]) | |
| text, finish = resp.choices[0].message.content or "", resp.choices[0].finish_reason | |
| cut = scan(text) | |
| if cut is not None: | |
| text, finish = text[:cut], "loop" | |
| return {"image": path, "text": text, "finish": finish, "tokens": resp.usage.completion_tokens} | |
| async def main() -> None: | |
| ap = argparse.ArgumentParser(description=__doc__.splitlines()[0]) | |
| ap.add_argument("images", nargs="+") | |
| ap.add_argument("--url", default="http://127.0.0.1:8000/v1") | |
| ap.add_argument("--mode", choices=["text", "grounding"], default="text") | |
| ap.add_argument("--edge", type=int, default=2048) | |
| ap.add_argument("--concurrency", type=int, default=32) | |
| ap.add_argument("--out", help="write one JSON line per page here instead of printing Markdown") | |
| a = ap.parse_args() | |
| cli = AsyncOpenAI(base_url=a.url, api_key="x", timeout=3600) | |
| sem = asyncio.Semaphore(a.concurrency) | |
| rows = await asyncio.gather(*(read(cli, p, a.mode, a.edge, sem) for p in a.images)) | |
| if a.out: | |
| with open(a.out, "w", encoding="utf-8") as fh: | |
| for r in rows: | |
| fh.write(json.dumps(r, ensure_ascii=False) + "\n") | |
| else: | |
| for r in rows: | |
| print(f"<!-- {r['image']} finish={r['finish']} tokens={r['tokens']} -->\n{r['text']}\n") | |
| if __name__ == "__main__": | |
| asyncio.run(main()) | |