Spaces:
Sleeping
Sleeping
Create ReadImageTool.py
Browse files- tools/ReadImageTool.py +11 -0
tools/ReadImageTool.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import base64
|
| 2 |
+
|
| 3 |
+
class ReadImageTool(Tool):
|
| 4 |
+
name = "read_image"
|
| 5 |
+
description = "Reads an image file and returns its base64 string for Gemini."
|
| 6 |
+
inputs = {"file_path": {"type": "string"}}
|
| 7 |
+
output_type = "string"
|
| 8 |
+
|
| 9 |
+
def forward(self, file_path: str) -> str:
|
| 10 |
+
with open(file_path, "rb") as img:
|
| 11 |
+
return base64.b64encode(img.read()).decode("utf-8")
|