SmolVLM-256M-Instruct fine-tuned with LoRA on
RICO-Screen2Words for UI screenshot captioning. LoRA adapters were merged into the base model for single-artifact deployment.
1from PIL import Image
2import torch
3from transformers import AutoProcessor, AutoModelForImageTextToText
4
5model_id = "AmitPrakash/rico-smolvlm-full"
6processor = AutoProcessor.from_pretrained(model_id)
7model = AutoModelForImageTextToText.from_pretrained(
8 model_id, dtype=torch.bfloat16
9).cuda().eval()
10
11image = Image.open("screenshot.png").convert("RGB")
12messages = [{
13 "role": "user",
14 "content": [
15 {"type": "image"},
16 {"type": "text", "text": "Describe this UI screenshot accurately and concisely."}
17 ]
18}]
19text = processor.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
20inputs = {k: v.cuda() for k, v in processor(text=[text], images=[image], return_tensors="pt").items()}
21
22with torch.inference_mode():
23 out = model.generate(**inputs, max_new_tokens=96, do_sample=False)
24print(processor.batch_decode(out, skip_special_tokens=True)[0])
1from peft import PeftModel
2from transformers import AutoModelForImageTextToText, AutoProcessor
3import torch
4
5base = AutoModelForImageTextToText.from_pretrained(
6 "HuggingFaceTB/SmolVLM-256M-Instruct", dtype=torch.bfloat16
7)
8model = PeftModel.from_pretrained(base, "AmitPrakash/rico-smolvlm-lora")
9model = model.merge_and_unload().cuda().eval()
10processor = AutoProcessor.from_pretrained("AmitPrakash/rico-smolvlm-lora")
11
12# then run inference as above