Spaces:
Sleeping
Sleeping
| 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 | |