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