MediVox / brain.py
gauravgulati619's picture
Update brain.py
beeaee1 verified
raw
history blame contribute delete
995 Bytes
import os
from dotenv import load_dotenv
# Load environment variables
load_dotenv()
GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
import base64
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
def analyze_image_with_query(query, model, encoded_image):
client=Groq()
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": query
},
{
"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