Medapp / image_pipeline.py
mgbam's picture
Update image_pipeline.py
a055897 verified
raw
history blame
583 Bytes
from huggingface_hub import InferenceApi
from PIL import Image
import base64
from config import HF_IMAGE_MODEL, HF_TOKEN
# Initialize Hugging Face Inference API
inference = InferenceApi(repo_id=HF_IMAGE_MODEL, token=HF_TOKEN)
def analyze_medical_image(image_file):
"""
Analyze a medical image using the Hugging Face Inference API.
"""
with open(image_file, "rb") as img:
base64_image = base64.b64encode(img.read()).decode("utf-8")
response = inference(inputs={"image": base64_image})
return response.get("generated_text", "No insights generated.")