Skip to main content

Gradio工具

There are many 1000s of Gradio apps on Hugging Face Spaces. This library puts them at the tips of your LLM's fingers 🦾

具体来说,gradio-tools是一个Python库,用于将Gradio应用程序转换为可以被大型语言模型(LLM)代理使用的工具,以完成其任务。例如,LLM可以使用Gradio工具来转录它在网上找到的语音录音,然后为您进行摘要。或者它可以使用另一个Gradio工具来对您的Google Drive上的文档应用OCR,然后回答相关问题。

如果您想使用不是预先构建的工具之一的空间,创建自己的工具非常容易。请参阅gradio-tools文档的此部分,了解如何操作。欢迎所有贡献!

# !pip install gradio_tools

使用工具

from gradio_tools.tools import StableDiffusionTool
local_file_path = StableDiffusionTool().langchain.run(
"请创建一张狗骑滑板的照片"
)
local_file_path
    已加载为API:https://gradio-client-demos-stable-diffusion.hf.space ✔

作业状态:Status.STARTING eta:None





'/Users/harrisonchase/workplace/langchain/docs/modules/agents/tools/integrations/b61c1dd9-47e2-46f1-a47c-20d27640993d/tmp4ap48vnm.jpg'
from PIL import Image
im = Image.open(local_file_path)
display(im)
    
![png](_gradio_tools_files/output_7_0.png)

在代理中使用

from langchain.agents import initialize_agent
from langchain.llms import OpenAI
from gradio_tools.tools import (
StableDiffusionTool,
ImageCaptioningTool,
StableDiffusionPromptGeneratorTool,
TextToVideoTool,
)

from langchain.memory import ConversationBufferMemory

llm = OpenAI(temperature=0)
memory = ConversationBufferMemory(memory_key="chat_history")
tools = [
StableDiffusionTool().langchain,
ImageCaptioningTool().langchain,
StableDiffusionPromptGeneratorTool().langchain,
TextToVideoTool().langchain,
]


agent = initialize_agent(
tools, llm, memory=memory, agent="conversational-react-description", verbose=True
)
output = agent.run(
input=(
"请创建一张狗骑滑板的照片 "
"但在使用图像生成器之前改进我的提示。"
"请为生成的图像添加标题并创建一个视频。"
)
)
    已加载为API:https://gradio-client-demos-stable-diffusion.hf.space ✔
已加载为API:https://taesiri-blip-2.hf.space ✔
已加载为API:https://microsoft-promptist.hf.space ✔
已加载为API:https://damo-vilab-modelscope-text-to-video-synthesis.hf.space ✔


> 进入新的AgentExecutor链...

思考:我需要使用工具吗?是的
动作:StableDiffusionPromptGenerator
动作输入:一只狗骑滑板
作业状态:Status.STARTING eta:None

观察结果:一只狗骑滑板,数字绘画,artstation,概念艺术,平滑,清晰焦点,插图,艺术家artgerm和greg rutkowski和alphonse mucha
思考:我需要使用工具吗?是的
动作:StableDiffusion
动作输入:一只狗骑滑板,数字绘画,artstation,概念艺术,平滑,清晰焦点,插图,艺术家artgerm和greg rutkowski和alphonse mucha
作业状态:Status.STARTING eta:None

作业状态:Status.PROCESSING eta:None

观察结果:/Users/harrisonchase/workplace/langchain/docs/modules/agents/tools/integrations/2e280ce4-4974-4420-8680-450825c31601/tmpfmiz2g1c.jpg
思考:我需要使用工具吗?是的
动作:ImageCaptioner
动作输入:/Users/harrisonchase/workplace/langchain/docs/modules/agents/tools/integrations/2e280ce4-4974-4420-8680-450825c31601/tmpfmiz2g1c.jpg
作业状态:Status.STARTING eta:None

观察结果:一幅狗坐在滑板上的画
思考:我需要使用工具吗?是的
动作:TextToVideo
动作输入:一幅狗坐在滑板上的画
作业状态:Status.STARTING eta:None
由于此应用程序的流量较大,预测大约需要73秒。为了更快地进行预测而无需排队等待,您可以使用:Client.duplicate(damo-vilab/modelscope-text-to-video-synthesis)复制空间。

作业状态:Status.IN_QUEUE eta:73.89824726581574
由于此应用程序的流量较大,预测大约需要42秒。为了更快地进行预测而无需排队等待,您可以使用:Client.duplicate(damo-vilab/modelscope-text-to-video-synthesis)复制空间。

作业状态:Status.IN_QUEUE eta:42.49370198879602

作业状态:Status.IN_QUEUE eta:21.314297944849187

观察结果:/var/folders/bm/ylzhm36n075cslb9fvvbgq640000gn/T/tmp5snj_nmzf20_cb3m.mp4
思考:我需要使用工具吗?不需要
AI:这是一段描述一幅狗坐在滑板上的画的视频。

> 完成链。