Update image_pipeline.py
Browse files- image_pipeline.py +11 -10
image_pipeline.py
CHANGED
@@ -1,16 +1,17 @@
|
|
1 |
-
from
|
2 |
from PIL import Image
|
3 |
-
|
|
|
4 |
|
5 |
-
#
|
6 |
-
|
7 |
-
model = AutoModelForVision2Seq.from_pretrained(HF_IMAGE_MODEL)
|
8 |
|
9 |
def analyze_medical_image(image_file):
|
10 |
"""
|
11 |
-
|
12 |
"""
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
|
|
|
1 |
+
from huggingface_hub import InferenceApi
|
2 |
from PIL import Image
|
3 |
+
import base64
|
4 |
+
from config import HF_IMAGE_MODEL, HF_TOKEN
|
5 |
|
6 |
+
# Initialize Hugging Face Inference API
|
7 |
+
inference = InferenceApi(repo_id=HF_IMAGE_MODEL, token=HF_TOKEN)
|
|
|
8 |
|
9 |
def analyze_medical_image(image_file):
|
10 |
"""
|
11 |
+
Analyze a medical image using the Hugging Face Inference API.
|
12 |
"""
|
13 |
+
with open(image_file, "rb") as img:
|
14 |
+
base64_image = base64.b64encode(img.read()).decode("utf-8")
|
15 |
+
|
16 |
+
response = inference(inputs={"image": base64_image})
|
17 |
+
return response.get("generated_text", "No insights generated.")
|