mjtaherikia's picture
New model used for image tool.
e1031ca
Raw History Blame Contribute Delete
880 Bytes
import requests
from google import genai
from google.genai import types
from smolagents import tool
from modules.prompts import image_description_prompt
@tool
def image_description(question: str, image_url: str) -> str:
"""
Recieves an image url and analyze it first, then return a what is needed based on prompt.
Args:
question: a question about given image
image_url: the url of image which should be considered as a reference for answering the question.
"""
image_bytes = requests.get(image_url).content
image = types.Part.from_bytes(
data=image_bytes, mime_type="image/jpeg"
)
client = genai.Client()
response = client.models.generate_content(
model="gemini-2.5-flash-preview-05-20",
contents=[image_description_prompt.format(question=question), image],
)
return response.text