Update image_pipeline.py
Browse files- image_pipeline.py +14 -6
image_pipeline.py
CHANGED
@@ -1,17 +1,25 @@
|
|
1 |
-
from transformers import
|
2 |
from PIL import Image
|
3 |
|
4 |
-
from config import HF_IMAGE_MODEL
|
5 |
|
6 |
-
# Load the Hugging Face model for medical image analysis
|
7 |
-
|
8 |
-
|
9 |
|
10 |
def analyze_medical_image(image_file):
|
11 |
"""
|
12 |
Process and analyze a medical image to generate diagnostic insights.
|
13 |
"""
|
|
|
14 |
image = Image.open(image_file).convert("RGB")
|
|
|
|
|
15 |
inputs = processor(images=image, return_tensors="pt")
|
|
|
|
|
16 |
outputs = model.generate(**inputs, max_length=256)
|
17 |
-
|
|
|
|
|
|
|
|
1 |
+
from transformers import BlipProcessor, BlipForConditionalGeneration
|
2 |
from PIL import Image
|
3 |
|
4 |
+
from config import HF_IMAGE_MODEL
|
5 |
|
6 |
+
# Load the Hugging Face processor and model for medical image analysis
|
7 |
+
processor = BlipProcessor.from_pretrained(HF_IMAGE_MODEL)
|
8 |
+
model = BlipForConditionalGeneration.from_pretrained(HF_IMAGE_MODEL)
|
9 |
|
10 |
def analyze_medical_image(image_file):
|
11 |
"""
|
12 |
Process and analyze a medical image to generate diagnostic insights.
|
13 |
"""
|
14 |
+
# Open the image file
|
15 |
image = Image.open(image_file).convert("RGB")
|
16 |
+
|
17 |
+
# Preprocess the image and prepare inputs
|
18 |
inputs = processor(images=image, return_tensors="pt")
|
19 |
+
|
20 |
+
# Generate outputs
|
21 |
outputs = model.generate(**inputs, max_length=256)
|
22 |
+
|
23 |
+
# Decode and return the generated text
|
24 |
+
result = processor.decode(outputs[0], skip_special_tokens=True)
|
25 |
+
return result
|