First_agent_template / tools /image_caption.py
sayed99's picture
image caption, image generation tool added
15f4de2
raw
history blame contribute delete
757 Bytes
from gradio_client import Client, handle_file
from typing import Any, Optional
from smolagents.tools import Tool
class ImageCaptionTool(Tool):
name = "image_caption"
description = "Provides a caption for the given image."
inputs = {'image_path': {'type': 'any',
'description': 'The image path for which to generate a caption.'}}
output_type = "string"
def forward(self, image_path: Any) -> Any:
client = Client("hysts/image-captioning-with-blip")
result = client.predict(
image=handle_file(image_path),
text="A picture of",
api_name="/caption"
)
return result
def __init__(self, *args, **kwargs):
self.is_initialized = False