Medapp / image_pipeline.py
mgbam's picture
Update image_pipeline.py
4753f3a verified
raw
history blame
771 Bytes
from transformers import AutoProcessor, AutoModelForImageTextToText
from PIL import Image
import torch
from config import HF_IMAGE_MODEL
# Load the advanced vision-language model for medical images
processor = AutoProcessor.from_pretrained(HF_IMAGE_MODEL)
model = AutoModelForImageTextToText.from_pretrained(HF_IMAGE_MODEL)
def analyze_medical_image(image_file):
"""
Performs advanced medical image analysis.
Returns a text explanation or diagnostic insight from the model.
"""
image = Image.open(image_file).convert("RGB")
inputs = processor(images=image, return_tensors="pt").to(model.device)
# Inference
outputs = model.generate(**inputs, max_length=256)
return processor.batch_decode(outputs, skip_special_tokens=True)[0]