|
from transformers import BlipProcessor, BlipForConditionalGeneration |
|
from PIL import Image |
|
|
|
from config import HF_IMAGE_MODEL |
|
|
|
|
|
processor = BlipProcessor.from_pretrained(HF_IMAGE_MODEL) |
|
model = BlipForConditionalGeneration.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) |
|
|
|
|
|
result = processor.decode(outputs[0], skip_special_tokens=True) |
|
return result |
|
|