File size: 1,549 Bytes
1bbda65
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
53
54
import os
from dotenv import load_dotenv
from groq import Groq
import base64 #bit to string


#setup1 groq api setup
load_dotenv()
GROQ_API_KEY = os.environ.get("GROQ_API_KEY")
client = Groq(api_key=GROQ_API_KEY)



#setup2 the image into encoded formate
# image_path = "acne.jpg"
model = "llama-3.2-90b-vision-preview"
def encodeimage(image_path):
    if not os.path.exists(image_path):
        raise FileNotFoundError(f"Image file not found: {image_path}")
    with open(image_path, "rb") as image_file:
        return base64.b64encode(image_file.read()).decode("utf-8")
    

    #step3 Setup the grof for vision 
def AnalyzeImagewithQuery(query,encode_imgae):
    messages = [
        {
            "role" : "user",
            "content" : [
                {
                    "type" : "text",
                    "text" : query
                },
                {
                    "type": "image_url",
                    "image_url": {
                        "url": f"data:image/jpeg;base64,{encode_imgae}"
                    }
                }

            ]
        }
    ]
    chat_completion = client.chat.completions.create(
        messages = messages,
        model = "meta-llama/llama-4-scout-17b-16e-instruct",
        temperature = 0.7
    )
    return chat_completion.choices[0].message.content

if __name__ == "__main__":
    query = "What happen with my face can you analyze that?"
    e_image=encodeimage()
    AnalyzeImagewithQuery(encode_imgae=e_image,query=query)