Views
No views yet
1from transformers import AutoProcessor, AutoModelForImageTextToText
2from PIL import Image
3import torch
4
5model = AutoModelForImageTextToText.from_pretrained("MedeHealth/medgemma-chest-xray-v2", torch_dtype=torch.bfloat16, device_map="auto")
6processor = AutoProcessor.from_pretrained("MedeHealth/medgemma-chest-xray-v2")
7
8image = Image.open("chest_xray.png").convert("RGB")
9messages = [{"role": "user", "content": [{"type": "image"}, {"type": "text", "text": "Analise esta radiografia de tórax."}]}]
10
11text = processor.apply_chat_template(messages, add_generation_prompt=True, tokenize=False)
12inputs = processor(text=text, images=[image], return_tensors="pt").to(model.device)
13
14with torch.inference_mode():
15 outputs = model.generate(**inputs, max_new_tokens=512, do_sample=False)
16
17print(processor.decode(outputs[0], skip_special_tokens=True))