Spaces:
Runtime error
Runtime error
Download tools/ReadImageTool.py from Sborole/Sborole-Final-Assignment: direct link, hf CLI and curl.
- Browser
- Download file 513 Bytes
-
https://huggingface.co/spaces/Sborole/Sborole-Final-Assignment/resolve/12b457dcdc6927a2e920342df7d8f6d373b5cadd/tools/ReadImageTool.py
- Command line
-
hf download hf://spaces/Sborole/Sborole-Final-Assignment@12b457dcdc6927a2e920342df7d8f6d373b5cadd/tools/ReadImageTool.py
-
curl -L -o ReadImageTool.py https://huggingface.co/spaces/Sborole/Sborole-Final-Assignment/resolve/12b457dcdc6927a2e920342df7d8f6d373b5cadd/tools/ReadImageTool.py
513 Bytes
| import base64 | |
| from smolagents.tools import Tool | |
| class ReadImageTool(Tool): | |
| name = "read_image" | |
| description = "Reads an image file and returns its base64 string for Gemini." | |
| inputs = { | |
| "file_path": { | |
| "type": "string", | |
| "description": "The full path of the text file to read" | |
| } | |
| } | |
| output_type = "string" | |
| def forward(self, file_path: str) -> str: | |
| with open(file_path, "rb") as img: | |
| return base64.b64encode(img.read()).decode("utf-8") |