Views
No views yet
| Item | Value |
|---|---|
| Base Model | Qwen/Qwen3.5-4B |
| Fine-tune Method | LoRA (PEFT) |
| LoRA Rank | 32 |
| LoRA Alpha | 64 |
| LoRA Dropout | 0.05 |
| Target Modules | all-linear (language_model) |
| Training Framework | ms-swift v4.3.0 |
| Precision | bfloat16 |
| Max Sequence Length | 10240 |
1pip install torch transformers peft accelerate pillow qwen_vl_utils
2# Or use ms-swift (recommended):
3pip install ms-swift[all]1from htmlgen_infer import HTMLGenModel
2
3model = HTMLGenModel(
4 adapter_path="Yesianrohn", # or local path to this repo
5 base_model="Qwen/Qwen3.5-4B", # auto-detected from adapter_config.json
6 merge_lora=True,
7)
8
9# Single image inference
10html_output = model.predict("path/to/document_image.png")
11print(html_output)
12
13# Batch inference
14results = model.predict_batch(["img1.png", "img2.png"])1import torch
2from transformers import AutoProcessor, AutoModelForCausalLM
3from peft import PeftModel
4from PIL import Image
5
6# Load base model
7base_model_id = "Qwen/Qwen3.5-4B"
8model = AutoModelForCausalLM.from_pretrained(
9 base_model_id,
10 torch_dtype=torch.bfloat16,
11 device_map="auto",
12 trust_remote_code=True,
13)
14processor = AutoProcessor.from_pretrained(base_model_id, trust_remote_code=True)
15
16# Load LoRA adapter
17model = PeftModel.from_pretrained(model, "Yesianrohn")
18model = model.merge_and_unload() # Optional: merge for faster inference
19
20# Prepare input
21image = Image.open("document.png").convert("RGB")
22system_prompt = (
23 "You are an expert document parser. Given an image of a document page, "
24 "reconstruct its source as a single complete, self-contained HTML5 "
25 "document. Faithfully preserve the original layout, typography, tables, "
26 "formulas, and visual hierarchy using inline CSS where appropriate. "
27 "Output only the HTML source, with no explanations, no markdown fences, "
28 "and no extra prose."
29)
30user_prompt = (
31 "Convert this document page into a complete HTML document. "
32 "Preserve the layout, headings, tables, and formulas exactly as shown. "
33 "Return only the HTML source."
34)
35
36messages = [
37 {"role": "system", "content": system_prompt},
38 {"role": "user", "content": [
39 {"type": "image", "image": image},
40 {"type": "text", "text": user_prompt},
41 ]},
42]
43
44text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
45inputs = processor(text=[text], images=[image], return_tensors="pt").to(model.device)
46
47output_ids = model.generate(**inputs, max_new_tokens=10240, temperature=0.0, do_sample=False)
48output_text = processor.batch_decode(output_ids[:, inputs.input_ids.shape[1]:], skip_special_tokens=True)[0]
49print(output_text)1# Direct inference with swift
2swift infer \
3 --model Qwen/Qwen3.5-4B \
4 --adapters Yesianrohn \
5 --merge_lora true \
6 --torch_dtype bfloat16 \
7 --stream falseYou are an expert document parser. Given an image of a document page, reconstruct its source as a single complete, self-contained HTML5 document. Faithfully preserve the original layout, typography, tables, formulas, and visual hierarchy using inline CSS where appropriate. Output only the HTML source, with no explanations, no markdown fences, and no extra prose.