File size: 880 Bytes
407a734
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e1031ca
407a734
 
 
 
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
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