Image-Text-to-Text
Transformers
Safetensors
English
Russian
qwen3_vl
vision-language-model
structured-extraction
table-extraction
financial-tables
qwen3-vl
vlm
dora
conversational
Instructions to use Glazkov/structured-extractor-qwen3vl-4b-exp93 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Glazkov/structured-extractor-qwen3vl-4b-exp93 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Glazkov/structured-extractor-qwen3vl-4b-exp93") 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 AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("Glazkov/structured-extractor-qwen3vl-4b-exp93") model = AutoModelForMultimodalLM.from_pretrained("Glazkov/structured-extractor-qwen3vl-4b-exp93", 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=40) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Glazkov/structured-extractor-qwen3vl-4b-exp93 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Glazkov/structured-extractor-qwen3vl-4b-exp93" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Glazkov/structured-extractor-qwen3vl-4b-exp93", "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/Glazkov/structured-extractor-qwen3vl-4b-exp93
- SGLang
How to use Glazkov/structured-extractor-qwen3vl-4b-exp93 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 "Glazkov/structured-extractor-qwen3vl-4b-exp93" \ --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": "Glazkov/structured-extractor-qwen3vl-4b-exp93", "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 "Glazkov/structured-extractor-qwen3vl-4b-exp93" \ --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": "Glazkov/structured-extractor-qwen3vl-4b-exp93", "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 Glazkov/structured-extractor-qwen3vl-4b-exp93 with Docker Model Runner:
docker model run hf.co/Glazkov/structured-extractor-qwen3vl-4b-exp93
Add examples/batch.py
Browse files- examples/batch.py +81 -0
examples/batch.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Batch extraction over a directory of table-cropped images.
|
| 2 |
+
|
| 3 |
+
Looks for ``<stem>.md`` alongside each image; if found, passes its contents
|
| 4 |
+
as the ``markdown`` disambiguator. Without markdown the model picks an
|
| 5 |
+
arbitrary plausible table and quality drops significantly.
|
| 6 |
+
|
| 7 |
+
Usage:
|
| 8 |
+
python examples/batch.py <image_dir> [--preset quality|fast] [--out results.jsonl]
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import argparse
|
| 12 |
+
import json
|
| 13 |
+
import sys
|
| 14 |
+
import time
|
| 15 |
+
from pathlib import Path
|
| 16 |
+
|
| 17 |
+
sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
|
| 18 |
+
|
| 19 |
+
from inference import PRESETS, StructuredExtractor
|
| 20 |
+
|
| 21 |
+
CHECKPOINT = "Glazkov/structured-extractor-qwen3vl-4b-exp93"
|
| 22 |
+
IMAGE_EXTS = {".png", ".jpg", ".jpeg", ".webp", ".bmp", ".tif", ".tiff"}
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def parse_args() -> argparse.Namespace:
|
| 26 |
+
p = argparse.ArgumentParser(description=__doc__)
|
| 27 |
+
p.add_argument("image_dir", type=Path, help="Directory with table-crop images")
|
| 28 |
+
p.add_argument(
|
| 29 |
+
"--preset",
|
| 30 |
+
choices=list(PRESETS),
|
| 31 |
+
default="quality",
|
| 32 |
+
help="quality (beam=4 + rp=1.1), balanced (beam=4), fast (greedy). Default: quality.",
|
| 33 |
+
)
|
| 34 |
+
p.add_argument(
|
| 35 |
+
"--out",
|
| 36 |
+
type=Path,
|
| 37 |
+
default=Path("results.jsonl"),
|
| 38 |
+
help="Path to JSONL output file (one record per image).",
|
| 39 |
+
)
|
| 40 |
+
return p.parse_args()
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def main() -> None:
|
| 44 |
+
args = parse_args()
|
| 45 |
+
paths = sorted(p for p in args.image_dir.iterdir() if p.suffix.lower() in IMAGE_EXTS)
|
| 46 |
+
if not paths:
|
| 47 |
+
sys.exit(f"No images found in {args.image_dir}")
|
| 48 |
+
|
| 49 |
+
markdowns: list[str | None] = []
|
| 50 |
+
for p in paths:
|
| 51 |
+
md_path = p.with_suffix(".md")
|
| 52 |
+
markdowns.append(md_path.read_text(encoding="utf-8") if md_path.exists() else None)
|
| 53 |
+
print(f"Loaded {sum(1 for m in markdowns if m)}/{len(paths)} markdown sidecars.")
|
| 54 |
+
|
| 55 |
+
print(f"Loading checkpoint {CHECKPOINT} ...")
|
| 56 |
+
extractor = StructuredExtractor.from_pretrained(CHECKPOINT)
|
| 57 |
+
|
| 58 |
+
print(f"Running '{args.preset}' over {len(paths)} images ...")
|
| 59 |
+
t0 = time.time()
|
| 60 |
+
results = extractor.extract_batch(
|
| 61 |
+
paths,
|
| 62 |
+
preset=args.preset,
|
| 63 |
+
markdown_batch=markdowns,
|
| 64 |
+
batch_size=1,
|
| 65 |
+
return_raw=False,
|
| 66 |
+
)
|
| 67 |
+
elapsed = time.time() - t0
|
| 68 |
+
|
| 69 |
+
with args.out.open("w", encoding="utf-8") as f:
|
| 70 |
+
for path, result in zip(paths, results):
|
| 71 |
+
record = {"image": str(path), "parameters": result["parameters"]}
|
| 72 |
+
f.write(json.dumps(record, ensure_ascii=False) + "\n")
|
| 73 |
+
|
| 74 |
+
print(
|
| 75 |
+
f"\nDone in {elapsed:.1f}s ({elapsed / len(paths):.2f}s/image). "
|
| 76 |
+
f"Wrote {len(paths)} records to {args.out}"
|
| 77 |
+
)
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
if __name__ == "__main__":
|
| 81 |
+
main()
|