Spaces:
Running
Running
| 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"))) |