File size: 856 Bytes
9aec363 4753f3a 9606bd7 9aec363 4753f3a 9aec363 efc6213 4753f3a efc6213 9606bd7 efc6213 9aec363 9606bd7 9aec363 9606bd7 9aec363 9606bd7 9aec363 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
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
|