File size: 2,774 Bytes
e67043b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
from xml.dom.pulldom import SAX2DOM
from ..tool import Tool
from gradio_tools.tools import (
    BarkTextToSpeechTool,
    StableDiffusionTool,
    DocQueryDocumentAnsweringTool,
    ImageCaptioningTool,
    StableDiffusionPromptGeneratorTool,
    TextToVideoTool,
    ImageToMusicTool,
    WhisperAudioTranscriptionTool,
    ClipInterrogatorTool,
)
from gradio_client.client import Job
from gradio_client.utils import QueueError
import time


def build_tool(config) -> Tool:
    tool = Tool(
        "GradioTool",
        "Gradio_tools Converter",
        name_for_model="gradio_tool",
        description_for_model="Python library for converting Gradio apps into tools that can be leveraged by a large language model (LLM)-based agent to complete its task.",
        logo_url="https://your-app-url.com/.well-known/logo.png",
        contact_email="[email protected]",
        legal_info_url="[email protected]",
    )

    @tool.get("/get_bark")
    def bark(input: str) -> str:
        """Converting text into sounds that sound like a human read it."""
        bk = BarkTextToSpeechTool()
        return bk.run(input)

    @tool.get("/get_qa")
    def qa(input: str) -> str:
        """Answering questions from the image of the document."""
        qa = DocQueryDocumentAnsweringTool()
        return qa.run(input)

    @tool.get("/get_imagecaption")
    def imagecaption(input: str) -> str:
        """Creating a caption for an image."""
        ic = ImageCaptioningTool()
        return ic.run(input)

    @tool.get("/get_promptgenerator")
    def promptgenerator(input: str) -> str:
        """Generating a prompt for stable diffusion and other image and video generators based on text input."""
        pg = StableDiffusionPromptGeneratorTool()
        return pg.run(input)

    @tool.get("/get_stablediffusion")
    def stablediffusion(input: str) -> str:
        """generate images based on text input."""
        sd = StableDiffusionTool()
        return sd.run(input)

    @tool.get("/get_texttovideo")
    def texttovideo(input: str) -> str:
        """Creating videos from text."""
        tv = TextToVideoTool()
        return tv.run(input)

    @tool.get("/get_imgtomsc")
    def imgtomsc(input: str) -> str:
        """Creating music from images."""
        im = ImageToMusicTool()
        return im.run(input)

    @tool.get("/get_audiotrans")
    def imgtomsc(input: str) -> str:
        """Transcribing an audio file track into text transcript."""
        at = WhisperAudioTranscriptionTool()
        return at.run(input)

    @tool.get("/get_imgprompt")
    def imgprompt(input: str) -> str:
        """Creating a prompt for StableDiffusion that matches the input image."""
        ci = ClipInterrogatorTool()
        return ci.run(input)

    return tool