Upload a chest X-ray → the system retrieves the most visually similar
historical case (CLIP + FAISS) → injects it as context →
fine-tuned Qwen2.5-VL 7B generates a findings paragraph.
1from unsloth import FastVisionModel
2from PIL import Image
3import torch
4
5model, tokenizer = FastVisionModel.from_pretrained(
6 model_name="mahdisetti/xray-qwen-lora",
7 load_in_4bit=True,
8)
9FastVisionModel.for_inference(model)
10
11image = Image.open("your_xray.jpg").convert("RGB")
12image.thumbnail((512, 512))
13
14messages = [
15 {
16 "role": "user",
17 "content": [
18 {"type": "image", "image": image},
19 {"type": "text", "text": (
20 "Write only one short radiology findings paragraph "
21 "under 50 words. Mention the main visible abnormality "
22 "and its anatomical location."
23 )},
24 ],
25 }
26]
27
28input_text = tokenizer.apply_chat_template(
29 messages, add_generation_prompt=True
30)
31inputs = tokenizer(
32 image, input_text,
33 add_special_tokens=False,
34 return_tensors="pt"
35).to("cuda")
36
37with torch.no_grad():
38 outputs = model.generate(
39 **inputs,
40 max_new_tokens=70,
41 do_sample=False,
42 repetition_penalty=1.3,
43 no_repeat_ngram_size=5,
44 )
45
46new_tokens = outputs[0][inputs["input_ids"].shape[-1]:]
47print(tokenizer.decode(new_tokens, skip_special_tokens=True))
FAISS index and report pickle stored at
mahdisetti/xray-rag-files