Medapp / image_pipeline.py
mgbam's picture
Update image_pipeline.py
9aec363 verified
raw
history blame contribute delete
856 Bytes
from transformers import BlipProcessor, BlipForConditionalGeneration
from PIL import Image
from config import HF_IMAGE_MODEL
# Load the Hugging Face processor and model for medical image analysis
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.
"""
# Open the image file
image = Image.open(image_file).convert("RGB")
# Preprocess the image and prepare inputs
inputs = processor(images=image, return_tensors="pt")
# Generate outputs
outputs = model.generate(**inputs, max_length=256)
# Decode and return the generated text
result = processor.decode(outputs[0], skip_special_tokens=True)
return result