Update image_pipeline.py
Browse files- image_pipeline.py +2 -7
image_pipeline.py
CHANGED
@@ -1,21 +1,16 @@
|
|
1 |
from transformers import AutoProcessor, AutoModelForImageTextToText
|
2 |
from PIL import Image
|
3 |
-
import torch
|
4 |
-
|
5 |
from config import HF_IMAGE_MODEL
|
6 |
|
7 |
-
# Load
|
8 |
processor = AutoProcessor.from_pretrained(HF_IMAGE_MODEL)
|
9 |
model = AutoModelForImageTextToText.from_pretrained(HF_IMAGE_MODEL)
|
10 |
|
11 |
def analyze_medical_image(image_file):
|
12 |
"""
|
13 |
-
|
14 |
-
Returns a text explanation or diagnostic insight from the model.
|
15 |
"""
|
16 |
image = Image.open(image_file).convert("RGB")
|
17 |
inputs = processor(images=image, return_tensors="pt").to(model.device)
|
18 |
-
|
19 |
-
# Inference
|
20 |
outputs = model.generate(**inputs, max_length=256)
|
21 |
return processor.batch_decode(outputs, skip_special_tokens=True)[0]
|
|
|
1 |
from transformers import AutoProcessor, AutoModelForImageTextToText
|
2 |
from PIL import Image
|
|
|
|
|
3 |
from config import HF_IMAGE_MODEL
|
4 |
|
5 |
+
# Load Hugging Face image model and processor
|
6 |
processor = AutoProcessor.from_pretrained(HF_IMAGE_MODEL)
|
7 |
model = AutoModelForImageTextToText.from_pretrained(HF_IMAGE_MODEL)
|
8 |
|
9 |
def analyze_medical_image(image_file):
|
10 |
"""
|
11 |
+
Process and analyze a medical image to generate diagnostic insights.
|
|
|
12 |
"""
|
13 |
image = Image.open(image_file).convert("RGB")
|
14 |
inputs = processor(images=image, return_tensors="pt").to(model.device)
|
|
|
|
|
15 |
outputs = model.generate(**inputs, max_length=256)
|
16 |
return processor.batch_decode(outputs, skip_special_tokens=True)[0]
|