-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrain.py
More file actions
52 lines (42 loc) · 1.34 KB
/
brain.py
File metadata and controls
52 lines (42 loc) · 1.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# if you dont use pipenv uncomment the following:
# from dotenv import load_dotenv
# load_dotenv()
#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-maverick-17b-128e-instruct"
model="meta-llama/llama-4-scout-17b-16e-instruct"
#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):
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