Download modules/tools.py from mjtaherikia/Final_Assignment_Template: direct link, hf CLI and curl.
- Browser
- Download file 880 Bytes
-
https://huggingface.co/spaces/mjtaherikia/Final_Assignment_Template/resolve/main/modules/tools.py
- Command line
-
hf download hf://spaces/mjtaherikia/Final_Assignment_Template/modules/tools.py
-
curl -L -o tools.py https://huggingface.co/spaces/mjtaherikia/Final_Assignment_Template/resolve/main/modules/tools.py
880 Bytes
| import requests | |
| from google import genai | |
| from google.genai import types | |
| from smolagents import tool | |
| from modules.prompts import image_description_prompt | |
| 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 | |