File size: 665 Bytes
9606bd7
4753f3a
9606bd7
a055897
4753f3a
9606bd7
 
 
efc6213
4753f3a
efc6213
9606bd7
efc6213
9606bd7
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from transformers import AutoProcessor, AutoModel
from PIL import Image

from config import HF_IMAGE_MODEL, HF_TOKEN

# Load the Hugging Face model for medical image analysis
model = AutoModel.from_pretrained(HF_IMAGE_MODEL, trust_remote_code=True)
processor = AutoProcessor.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")
    outputs = model.generate(**inputs, max_length=256)
    return processor.decode(outputs[0], skip_special_tokens=True)