Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] update load_tool #34683

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions docs/source/en/agents_advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,28 @@ You can leverage `gradio.Chatbot`to display your agent's thoughts using `stream_
```py
import gradio as gr
from transformers import (
load_tool,
ReactCodeAgent,
HfApiEngine,
stream_to_gradio,
)
from transformers.agents.tools import Tool
from huggingface_hub import InferenceClient

# Import tool from Hub
image_generation_tool = load_tool("m-ric/text-to-image")

class TextToImageTool(Tool):
description = "This is a tool that creates an image according to a prompt, which is a text description."
name = "image_generator"
inputs = {"prompt": {"type": "string", "description": "The image generator prompt. Don't hesitate to add details in the prompt to make the image look better, like 'high-res, photorealistic', etc."}}
output_type = "image"
model_sdxl = "stabilityai/stable-diffusion-xl-base-1.0"
client = InferenceClient(model_sdxl)


def forward(self, prompt):
return self.client.text_to_image(prompt)


image_generation_tool = TextToImageTool()
llm_engine = HfApiEngine("meta-llama/Meta-Llama-3-70B-Instruct")

# Initialize the agent with the image generation tool
Expand Down