File size: 757 Bytes
15f4de2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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