File size: 583 Bytes
a055897
4753f3a
a055897
 
4753f3a
a055897
 
efc6213
4753f3a
efc6213
a055897
efc6213
a055897
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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.")