|
from transformers import AutoProcessor, AutoModelForImageTextToText |
|
from PIL import Image |
|
import torch |
|
|
|
from config import HF_IMAGE_MODEL |
|
|
|
|
|
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) |
|
|
|
|
|
outputs = model.generate(**inputs, max_length=256) |
|
return processor.batch_decode(outputs, skip_special_tokens=True)[0] |
|
|