Spaces:
Running
Running
File size: 1,188 Bytes
17a5b4a |
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 |
from dotenv import load_dotenv
import base64
from groq import Groq
load_dotenv()
def load_image(image_path):
image_file = open(image_path, "rb")
return base64.b64encode(image_file.read()).decode("utf-8")
query = "Describe the condition of face briefly"
model = "meta-llama/llama-4-scout-17b-16e-instruct"
def analyze_image_with_query(model, query , 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(
model=model,
messages=messages,
)
print("Loading image...")
print(chat_completion.choices[0].message.content)
return chat_completion.choices[0].message.content
print(analyze_image_with_query(model, query, load_image("acne.jpg"))) |