class_docstr: A base class for the functions used by the agent. Subclass this and implement the `__call__` method as well as the
  following class attributes:
  
  - **description** (`str`) -- A short description of what your tool does, the inputs it expects and the output(s) it
    will return. For instance 'This is a tool that downloads a file from a `url`. It takes the `url` as input, and
    returns the text contained in the file'.
  - **name** (`str`) -- A performative name that will be used for your tool in the prompt to the agent. For instance
    `"text-classifier"` or `"image_generator"`.
  - **inputs** (`List[str]`) -- The list of modalities expected for the inputs (in the same order as in the call).
    Modalitiies should be `"text"`, `"image"` or `"audio"`. This is only used by `launch_gradio_demo` or to make a
    nice space from your tool.
  - **outputs** (`List[str]`) -- The list of modalities returned but the tool (in the same order as the return of the
    call method). Modalitiies should be `"text"`, `"image"` or `"audio"`. This is only used by `launch_gradio_demo`
    or to make a nice space from your tool.
  
  You can also override the method [`~Tool.setup`] if your tool as an expensive operation to perform before being
  usable (such as loading a model). [`~Tool.setup`] will be called the first time you use your tool, but not at
  instantiation.
class_docstr_tok: ["A","base","class","for","the","functions","used","by","the","agent",".","Subclass","this","and","implement","the","`","__call__","`","method","as","well","as","the","following","class","attributes",":","-","*","*","description","*","*","(","`","str","`",")","--","A","short","description","of","what","your","tool","does",",","the","inputs","it","expects","and","the","output","(","s",")","it","will","return",".","For","instance","'This","is","a","tool","that","downloads","a","file","from","a","`","url","`",".","It","takes","the","`","url","`","as","input",",","and","returns","the","text","contained","in","the","file","'",".","-","*","*","name","*","*","(","`","str","`",")","--","A","performative","name","that","will","be","used","for","your","tool","in","the","prompt","to","the","agent",".","For","instance","`","``","text-classifier","''","`","or","`","``","image_generator","''","`",".","-","*","*","inputs","*","*","(","`","List","[","str","]","`",")","--","The","list","of","modalities","expected","for","the","inputs","(","in","the","same","order","as","in","the","call",")",".","Modalitiies","should","be","`","``","text","''","`",",","`","``","image","''","`","or","`","``","audio","''","`",".","This","is","only","used","by","`","launch_gradio_demo","`","or","to","make","a","nice","space","from","your","tool",".","-","*","*","outputs","*","*","(","`","List","[","str","]","`",")","--","The","list","of","modalities","returned","but","the","tool","(","in","the","same","order","as","the","return","of","the","call","method",")",".","Modalitiies","should","be","`","``","text","''","`",",","`","``","image","''","`","or","`","``","audio","''","`",".","This","is","only","used","by","`","launch_gradio_demo","`","or","to","make","a","nice","space","from","your","tool",".","You","can","also","override","the","method","[","`","~Tool.setup","`","]","if","your","tool","as","an","expensive","operation","to","perform","before","being","usable","(","such","as","loading","a","model",")",".","[","`","~Tool.setup","`","]","will","be","called","the","first","time","you","use","your","tool",",","but","not","at","instantiation","."]
docstr: Saves the relevant code files for your tool so it can be pushed to the Hub. This will copy the code of your
  tool in `output_dir` as well as autogenerate:
  
  - a config file named `tool_config.json`
  - an `app.py` file so that your tool can be converted to a space
  - a `requirements.txt` containing the names of the module used by your tool (as detected when inspecting its
    code)
  
  You should only use this method to save tools that are defined in a separate module (not `__main__`).
  
  Args:
      output_dir (`str`): The folder in which you want to save your tool.
docstr_tok: ["Saves","the","relevant","code","files","for","your","tool","so","it","can","be","pushed","to","the","Hub",".","This","will","copy","the","code","of","your","tool","in","`","output_dir","`","as","well","as","autogenerate",":","-","a","config","file","named","`","tool_config.json","`","-","an","`","app.py","`","file","so","that","your","tool","can","be","converted","to","a","space","-","a","`","requirements.txt","`","containing","the","names","of","the","module","used","by","your","tool","(","as","detected","when","inspecting","its","code",")","You","should","only","use","this","method","to","save","tools","that","are","defined","in","a","separate","module","(","not","`","__main__","`",")",".","Args",":","output_dir","(","`","str","`",")",":","The","folder","in","which","you","want","to","save","your","tool","."]
code: def save(self, output_dir):
      """
      Saves the relevant code files for your tool so it can be pushed to the Hub. This will copy the code of your
      tool in `output_dir` as well as autogenerate:
  
      - a config file named `tool_config.json`
      - an `app.py` file so that your tool can be converted to a space
      - a `requirements.txt` containing the names of the module used by your tool (as detected when inspecting its
        code)
  
      You should only use this method to save tools that are defined in a separate module (not `__main__`).
  
      Args:
          output_dir (`str`): The folder in which you want to save your tool.
      """
      os.makedirs(output_dir, exist_ok=True)
      # Save module file
      if self.__module__ == "__main__":
          raise ValueError(
              f"We can't save the code defining {self} in {output_dir} as it's been defined in __main__. You "
              "have to put this code in a separate module so we can include it in the saved folder."
          )
      module_files = custom_object_save(self, output_dir)
  
      module_name = self.__class__.__module__
      last_module = module_name.split(".")[-1]
      full_name = f"{last_module}.{self.__class__.__name__}"
  
      # Save config file
      config_file = os.path.join(output_dir, "tool_config.json")
      if os.path.isfile(config_file):
          with open(config_file, "r", encoding="utf-8") as f:
              tool_config = json.load(f)
      else:
          tool_config = {}
  
      tool_config = {
          "tool_class": full_name,
          "description": self.description,
          "name": self.name,
      }
      with open(config_file, "w", encoding="utf-8") as f:
          f.write(
              json.dumps(tool_config, indent=2, sort_keys=True) + "\n"
          )
  
      # Save app file
      app_file = os.path.join(output_dir, "app.py")
      with open(app_file, "w", encoding="utf-8") as f:
          f.write(
              APP_FILE_TEMPLATE.format(
                  module_name=last_module,
                  class_name=self.__class__.__name__,
              )
          )
  
      # Save requirements file
      requirements_file = os.path.join(output_dir, "requirements.txt")
      imports = []
      for module in module_files:
          imports.extend(get_imports(module))
      imports = list(set(imports))
      with open(requirements_file, "w", encoding="utf-8") as f:
          f.write("\n".join(imports) + "\n")
  
imports: import base64
  import importlib
  import inspect
  import io
  import json
  import os
  import tempfile
  from typing import Any, Dict, List, Optional, Union
  from huggingface_hub import create_repo, hf_hub_download, metadata_update, upload_folder
  from huggingface_hub.utils import RepositoryNotFoundError, build_hf_headers, get_session
  from ..dynamic_module_utils import custom_object_save, get_class_from_dynamic_module, get_imports
  from ..image_utils import is_pil_image
  from ..models.auto import AutoProcessor
  from ..utils import CONFIG_NAME, cached_file, is_accelerate_available, is_torch_available, is_vision_available, logging
  from .agent_types import handle_agent_inputs, handle_agent_outputs
label_desc: Use image node_id 4 for calling the Tool obj's underlying member method code with example usage: obj.save(output_dir) without return types