from transformers import AutoProcessor, AutoModelForImageTextToText from PIL import Image from config import HF_IMAGE_MODEL # Load Hugging Face image model and processor processor = AutoProcessor.from_pretrained(HF_IMAGE_MODEL) model = AutoModelForImageTextToText.from_pretrained(HF_IMAGE_MODEL) def analyze_medical_image(image_file): """ Process and analyze a medical image to generate diagnostic insights. """ image = Image.open(image_file).convert("RGB") inputs = processor(images=image, return_tensors="pt").to(model.device) outputs = model.generate(**inputs, max_length=256) return processor.batch_decode(outputs, skip_special_tokens=True)[0]