Shortcuts

ImageToScribble

class agentlego.tools.ImageToScribble(device='cuda', toolmeta=None)[源代码]

A tool to convert image to a scribble sketch.

参数:
  • device (str) – The device to load the model. Defaults to ‘cuda’.

  • toolmeta (None | dict | ToolMeta) – The additional info of the tool. Defaults to None.

默认工具信息

  • 名称: ImageToScribble

  • 描述: This tool can generate a sketch scribble of an image.

  • 输入:

    • image (ImageIO)

  • 输出:

    • ImageIO

Examples

Use the tool directly (without agent)

from agentlego.apis import load_tool

# load tool
tool = load_tool('ImageToScribble', device='cuda')

# apply tool
scribble = tool('examples/demo.png')
print(scribble)

With Lagent

from lagent import ReAct, GPTAPI, ActionExecutor
from agentlego.apis import load_tool

# load tools and build agent
# please set `OPENAI_API_KEY` in your environment variable.
tool = load_tool('ImageToScribble', device='cuda').to_lagent()
agent = ReAct(GPTAPI(temperature=0.), action_executor=ActionExecutor([tool]))

# agent running with the tool.
img_path = 'examples/demo.png'
ret = agent.chat(f'Please draw the scribble sketch of the image `{img_path}`')
for step in ret.inner_steps[1:]:
    print('------')
    print(step['content'])

Set up

Before using the tool, please confirm you have installed the related dependencies by the below commands.

pip install -U controlnet_aux

Reference

The tool use controlnet_aux to generate an auxiliary scribble sketch that can be used in the ControlNet.