import torch from PIL import Image from transformers import AutoProcessor from unsloth import FastVisionModel # Import FastVisionModel model_id = "Willie999/Anidane" processor = AutoProcessor.from_pretrained(model_id) # Use FastVisionModel for loading the model, consistent with training # FastVisionModel.from_pretrained returns a tuple (model, processor), so we unpack it. model, _ = FastVisionModel.from_pretrained( model_name = model_id, # Use model_name for FastVisionModel torch_dtype=torch.bfloat16, device_map="auto" ) # Load a target retinal image image = Image.open("/content/red-eye-disease.jpg").convert("RGB") messages = [ { "role": "user", "content": [ {"type": "image"}, {"type": "text", "text": "Analyze this fundus/eye photograph. Provide a clear diagnostic assessment focusing on localized anomalies."} ] } ] prompt = processor.apply_chat_template(messages, add_generation_prompt=True) inputs = processor(text=prompt, images=image, return_tensors="pt").to(model.device) with torch.no_grad(): generated_ids = model.generate( input_ids=inputs["input_ids"], pixel_values=inputs["pixel_values"], # Explicitly pass pixel_values max_new_tokens=256, do_sample=False ) response = processor.batch_decode( generated_ids[:, inputs["input_ids"].shape[1]:], skip_special_tokens=True )[0] print("Anidane Analysis:", response)