Spaces:
Sleeping
Sleeping
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) |