AI_doctor / brain_of_the_doctor.py
Ruchir456's picture
Rename brain_of_the_doctor (3).py to brain_of_the_doctor.py
76e0107 verified
#Step1: Setup GROQ API key
import os
GROQ_API_KEY=os.environ.get("GROQ_API_KEY")
#Step2: Convert image to required format
import base64
#image_path="acne.jpg"
def encode_image(image_path):
image_file=open(image_path, "rb")
return base64.b64encode(image_file.read()).decode('utf-8')
#Step3: Setup Multimodal LLM
from groq import Groq
query="Is there something wrong with my face?"
model = "meta-llama/llama-4-scout-17b-16e-instruct"
#model="llama-3.2-90b-vision-preview" #Deprecated
def analyze_image_with_query(query, model, encoded_image=None):#here encoded_image=None because i just dont want to make in mandatory as i can audio input also
client = Groq()
messages = [
{
"role": "user",
"content": [
{"type": "text", "text": query}
]
}
]
# Only add image if it's present
if encoded_image:
messages[0]["content"].append({
"type": "image_url",
"image_url": {
"url": f"data:image/jpeg;base64,{encoded_image}",
}
})
chat_completion = client.chat.completions.create(
messages=messages,
model=model
)
return chat_completion.choices[0].message.content