File size: 771 Bytes
4753f3a
 
 
efc6213
4753f3a
 
 
 
 
efc6213
4753f3a
efc6213
4753f3a
 
efc6213
4753f3a
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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]