### Final Installation Rule Source: https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/extensions-builtin/forge_legacy_preprocessors/annotator/zoe/zoedepth/models/base_models/midas_repo/ros/midas_cpp/CMakeLists.txt This is the primary installation rule for the project, installing the target `${PROJECT_NAME}` as an archive, library, and runtime executable according to Catkin destinations. ```cmake install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} ) ``` -------------------------------- ### Python Function Examples Source: https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/backend/huggingface/Tencent-Hunyuan/HunyuanDiT-Diffusers/tokenizer/vocab.txt Demonstrates various Python functions for common programming tasks. Includes examples for string manipulation, data structures, and control flow. ```python def greet(name): """Greets the person passed in as a parameter""" print(f"Hello, {name}!") greet("World") ``` ```python def calculate_sum(numbers): """Calculates the sum of a list of numbers""" return sum(numbers) my_list = [1, 2, 3, 4, 5] print(f"Sum: {calculate_sum(my_list)}") ``` -------------------------------- ### Conda Environment Setup for PyTorch Source: https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/extensions-builtin/forge_preprocessor_normalbae/annotator/normalbae/models/submodules/efficientnet_repo/README.md Provides the necessary Conda commands to create and activate a new environment and install PyTorch with a specific CUDA toolkit version. This is a prerequisite for running the associated code. ```bash conda create -n torch-env conda activate torch-env conda install -c pytorch pytorch torchvision cudatoolkit=10.2 ``` -------------------------------- ### Install OpenVINO Source: https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/extensions-builtin/forge_legacy_preprocessors/annotator/zoe/zoedepth/models/base_models/midas_repo/README.md Installs the OpenVINO library using pip, which is required for using OpenVINO models. ```shell pip install openvino ``` -------------------------------- ### Geffnet Pip Installation and Usage Source: https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/extensions-builtin/forge_preprocessor_normalbae/annotator/normalbae/models/submodules/efficientnet_repo/README.md Provides instructions for installing the 'geffnet' library via pip and demonstrates how to create and use models for evaluation and training. It also shows how to create models as nn.Sequential containers. ```python # Install (after conda env/install): pip install geffnet # Eval use: import geffnet m = geffnet.create_model('mobilenetv3_large_100', pretrained=True) m.eval() # Train use: import geffnet # models can also be created by using the entrypoint directly m = geffnet.efficientnet_b2(pretrained=True, drop_rate=0.25, drop_connect_rate=0.2) m.train() # Create in a nn.Sequential container, for fast.ai, etc: import geffnet m = geffnet.mixnet_l(pretrained=True, drop_rate=0.25, drop_connect_rate=0.2, as_sequential=True) ``` -------------------------------- ### Install Libraries Source: https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/extensions-builtin/forge_legacy_preprocessors/annotator/zoe/zoedepth/models/base_models/midas_repo/ros/midas_cpp/CMakeLists.txt Installs the library target named `${PROJECT_NAME}`. It specifies destinations for archive, library, and runtime files, adhering to Catkin package conventions. ```cmake install(TARGETS ${PROJECT_NAME} ARCHIVE DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} LIBRARY DESTINATION ${CATKIN_PACKAGE_LIB_DESTINATION} RUNTIME DESTINATION ${CATKIN_GLOBAL_BIN_DESTINATION} ) ``` -------------------------------- ### Basic Python Script Example Source: https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/backend/huggingface/Tencent-Hunyuan/HunyuanDiT-Diffusers/tokenizer/vocab.txt A simple Python script demonstrating basic operations. This snippet is useful for understanding the fundamental structure and syntax used within the project. ```Python def greet(name): print(f"Hello, {name}!") greet("World") ``` -------------------------------- ### Advanced Installation (Git Clone) Source: https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/README.md Instructions for advanced users who want to install Forge as a branch of the original Stable Diffusion WebUI using Git. This allows reusing existing checkpoints and extensions. ```Batch @echo off REM Ensure Git and Python are installed and in your PATH. ECHO Cloning the Stable Diffusion WebUI Forge repository... ECHO git clone https://github.com/lllyasviel/stable-diffusion-webui-forge.git ECHO Navigating into the cloned directory... ECHO cd stable-diffusion-webui-forge ECHO Running the webui-user.bat script to start Forge... ECHO start /WAIT webui-user.bat ECHO For updates, use update.bat within the Forge directory. ``` -------------------------------- ### Download and Install MiDaS for ROS Source: https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/extensions-builtin/forge_legacy_preprocessors/annotator/zoe/zoedepth/models/base_models/midas_repo/ros/README.md Clones the MiDaS repository, sets up a ROS catkin workspace, copies necessary files, and builds the project. Includes downloading additional assets. ```bash source ~/.bashrc cd ~/ mkdir catkin_ws cd catkin_ws git clone https://github.com/isl-org/MiDaS mkdir src cp -r MiDaS/ros/* src chmod +x src/additions/*.sh chmod +x src/*.sh chmod +x src/midas_cpp/scripts/*.py cp src/additions/do_catkin_make.sh ./do_catkin_make.sh ./do_catkin_make.sh ./src/additions/downloads.sh ``` -------------------------------- ### Install Dependencies Source: https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/extensions-builtin/forge_legacy_preprocessors/annotator/zoe/zoedepth/models/base_models/midas_repo/README.md Installs project dependencies using Conda from the environment.yaml file and activates the specified Conda environment. ```shell conda env create -f environment.yaml conda activate midas-py310 ``` -------------------------------- ### Install Headers Source: https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/extensions-builtin/forge_legacy_preprocessors/annotator/zoe/zoedepth/models/base_models/midas_repo/ros/midas_cpp/CMakeLists.txt Installs header files for the `${PROJECT_NAME}` library. It targets files within `include/${PROJECT_NAME}/`, excluding any `.svn` directories. ```cmake install(DIRECTORY include/${PROJECT_NAME}/ DESTINATION ${CATKIN_PACKAGE_INCLUDE_DESTINATION} FILES_MATCHING PATTERN "*.h" PATTERN ".svn" EXCLUDE ) ``` -------------------------------- ### Python Function Example Source: https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/backend/huggingface/Tencent-Hunyuan/HunyuanDiT-Diffusers/tokenizer/vocab.txt A basic Python function demonstrating a common programming pattern. This snippet is self-contained and does not require external libraries. ```python def greet(name): """This function greets the person passed in as a parameter.""" print(f"Hello, {name}!") greet("World") ``` -------------------------------- ### List Available ControlNet Preprocessors Source: https://github.com/lllyasviel/stable-diffusion-webui-forge/wiki/ControlNet-Web-API Fetches a list of all available preprocessor modules for ControlNet from the Web API. This is useful for understanding which preprocessors can be used for image processing. ```Python import requests modules = requests.get("http://localhost:7860/controlnet/module_list").json()["module_list"] print(modules) # Expected output format: # [ # "None", # "softedge_pidinet", # "shuffle", # "seg_ofade20k", # "scribble_pidinet", # "reference_only", # "openpose_full", # "normalbae", # ... # ] ``` -------------------------------- ### Build Docker Image Source: https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/extensions-builtin/forge_legacy_preprocessors/annotator/zoe/zoedepth/models/base_models/midas_repo/README.md Builds the Docker image for the project. Ensure Docker and NVIDIA Docker runtime are installed. ```shell docker build -t midas . ``` -------------------------------- ### One-Click Installation Package Source: https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/README.md Provides a one-click installation package for Stable Diffusion WebUI Forge, including Git and Python. It is recommended to use the CUDA 12.1 + Pytorch 2.3.1 version. ```Batch @echo off REM This is a placeholder for the actual download command or script. REM The actual installation involves downloading a .7z file and extracting it. ECHO Downloading and installing Stable Diffusion WebUI Forge... REM Example: curl -L "https://github.com/lllyasviel/stable-diffusion-webui-forge/releases/download/latest/webui_forge_cu121_torch231.7z" -o webui_forge.7z REM Example: 7z x webui_forge.7z -o"./stable-diffusion-webui-forge" ECHO Please refer to the project's README for the exact installation steps. ECHO Download Link: https://github.com/lllyasviel/stable-diffusion-webui-forge/releases/download/latest/webui_forge_cu121_torch231.7z ECHO Update Script: update.bat ECHO Run Script: run.bat ``` -------------------------------- ### Project Setup and Execution Source: https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/html/extra-networks-tree-button.html Provides instructions for setting up and running the Stable Diffusion WebUI Forge project. This typically involves cloning the repository and executing a startup script. ```Shell git clone https://github.com/lllyasviel/stable-diffusion-webui-forge.git cd stable-diffusion-webui-forge ./webui.sh ``` -------------------------------- ### Install Other Files Source: https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/extensions-builtin/forge_legacy_preprocessors/annotator/zoe/zoedepth/models/base_models/midas_repo/ros/midas_cpp/CMakeLists.txt A placeholder for installing other project files, such as launch files or bag files, to the Catkin package share destination. ```cmake install(FILES # myfile1 # myfile2 DESTINATION ${CATKIN_PACKAGE_SHARE_DESTINATION} ) ``` -------------------------------- ### OpenAI Model Class Documentation Source: https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/backend/huggingface/Tencent-Hunyuan/HunyuanDiT-Diffusers/tokenizer/vocab.txt This section provides detailed documentation for the OpenAIModel class, including its constructor and methods. It outlines the parameters required for initialization and the expected behavior of the class. ```APIDOC OpenAIModel: __init__(model_name: str, provider: str = 'openai') - Initializes the OpenAIModel. - Parameters: - model_name: The name of the OpenAI model to use (e.g., "gpt-3.5-turbo", "gpt-4"). - provider: The provider to use for accessing the OpenAI API. Defaults to 'openai'. generate_response(prompt: str, **kwargs) -> str - Generates a text response from the OpenAI model based on the provided prompt. - Parameters: - prompt: The input text prompt for the model. - **kwargs: Additional keyword arguments to pass to the OpenAI API (e.g., temperature, max_tokens). - Returns: The generated text response from the model. get_model_name() -> str - Returns the name of the initialized OpenAI model. - Returns: The model name. ``` -------------------------------- ### Install Executable Source: https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/extensions-builtin/forge_legacy_preprocessors/annotator/zoe/zoedepth/models/base_models/midas_repo/ros/midas_cpp/CMakeLists.txt Installs the executable target named `${PROJECT_NAME}_node` to the runtime destination defined by Catkin. This is typically used for ROS nodes. ```cmake install(TARGETS ${PROJECT_NAME}_node RUNTIME DESTINATION ${CATKIN_PACKAGE_BIN_DESTINATION} ) ``` -------------------------------- ### Install ROS Melodic Dependencies Source: https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/extensions-builtin/forge_legacy_preprocessors/annotator/zoe/zoedepth/models/base_models/midas_repo/ros/README.md Installs ROS Melodic dependencies for Ubuntu 17.10/18.04 using a provided script. This is a prerequisite for running the MiDaS ROS node. ```bash wget https://raw.githubusercontent.com/isl-org/MiDaS/master/ros/additions/install_ros_melodic_ubuntu_17_18.sh ./install_ros_melodic_ubuntu_17_18.sh ``` -------------------------------- ### Install ROS Noetic Dependencies Source: https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/extensions-builtin/forge_legacy_preprocessors/annotator/zoe/zoedepth/models/base_models/midas_repo/ros/README.md Installs ROS Noetic dependencies for Ubuntu 20.04 using a provided script. This is a prerequisite for running the MiDaS ROS node. ```bash wget https://raw.githubusercontent.com/isl-org/MiDaS/master/ros/additions/install_ros_noetic_ubuntu_20.sh ./install_ros_noetic_ubuntu_20.sh ``` -------------------------------- ### CMake Project Setup and Dependencies Source: https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/extensions-builtin/forge_legacy_preprocessors/annotator/zoe/zoedepth/models/base_models/midas_repo/ros/midas_cpp/CMakeLists.txt Initializes the CMake project, sets the minimum version, and finds required ROS packages (cv_bridge, image_transport, roscpp, rospy, sensor_msgs, std_msgs) and system libraries like Boost and OpenCV. It also configures paths for PyTorch libraries. ```cmake cmake_minimum_required(VERSION 3.0.2) project(midas_cpp) # Compile as C++11, supported in ROS Kinetic and newer # add_compile_options(-std=c++11) # Find catkin macros and libraries # if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz) # is used, also find other catkin packages find_package(catkin REQUIRED COMPONENTS cv_bridge image_transport roscpp rospy sensor_msgs std_msgs ) # System dependencies are found with CMake's conventions # find_package(Boost REQUIRED COMPONENTS system) list(APPEND CMAKE_PREFIX_PATH "~/libtorch") list(APPEND CMAKE_PREFIX_PATH "/usr/local/lib/python3.6/dist-packages/torch/lib") list(APPEND CMAKE_PREFIX_PATH "/usr/local/lib/python2.7/dist-packages/torch/lib") if(NOT EXISTS "~/libtorch") if (EXISTS "/usr/local/lib/python3.6/dist-packages/torch") include_directories(/usr/local/include) include_directories(/usr/local/lib/python3.6/dist-packages/torch/include/torch/csrc/api/include) include_directories(/usr/local/lib/python3.6/dist-packages/torch/include) link_directories(/usr/local/lib) link_directories(/usr/local/lib/python3.6/dist-packages/torch/lib) set(CMAKE_PREFIX_PATH /usr/local/lib/python3.6/dist-packages/torch) set(Boost_USE_MULTITHREADED ON) set(Torch_DIR /usr/local/lib/python3.6/dist-packages/torch) elseif (EXISTS "/usr/local/lib/python2.7/dist-packages/torch") include_directories(/usr/local/include) include_directories(/usr/local/lib/python2.7/dist-packages/torch/include/torch/csrc/api/include) include_directories(/usr/local/lib/python2.7/dist-packages/torch/include) link_directories(/usr/local/lib) link_directories(/usr/local/lib/python2.7/dist-packages/torch/lib) set(CMAKE_PREFIX_PATH /usr/local/lib/python2.7/dist-packages/torch) set(Boost_USE_MULTITHREADED ON) set(Torch_DIR /usr/local/lib/python2.7/dist-packages/torch) endif() endif() find_package(Torch REQUIRED) find_package(OpenCV REQUIRED) include_directories( ${OpenCV_INCLUDE_DIRS} ) add_executable(midas_cpp src/main.cpp) target_link_libraries(midas_cpp "${TORCH_LIBRARIES}" "${OpenCV_LIBS} ${catkin_LIBRARIES}") set_property(TARGET midas_cpp PROPERTY CXX_STANDARD 14) ``` -------------------------------- ### Install LibTorch 1.7 with CUDA 11.0 on Jetson (ARM) Source: https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/extensions-builtin/forge_legacy_preprocessors/annotator/zoe/zoedepth/models/base_models/midas_repo/ros/README.md Installs LibTorch version 1.7.0 with CUDA 11.0 support for ARM-based Jetson devices. Includes Python dependencies and compilation tools. ```bash wget https://nvidia.box.com/shared/static/wa34qwrwtk9njtyarwt5nvo6imenfy26.whl -O torch-1.7.0-cp36-cp36m-linux_aarch64.whl sudo apt-get install python3-pip libopenblas-base libopenmpi-dev pip3 install Cython pip3 install numpy torch-1.7.0-cp36-cp36m-linux_aarch64.whl ``` -------------------------------- ### OpenAI Model Initialization Source: https://github.com/lllyasviel/stable-diffusion-webui-forge/blob/main/backend/huggingface/Tencent-Hunyuan/HunyuanDiT-Diffusers/tokenizer/vocab.txt This snippet demonstrates how to initialize an OpenAI model. It specifies the model name and optionally the provider, allowing for flexible integration with different OpenAI API versions or services. ```Python from forge.llm.openai import OpenAIModel # Initialize with default provider model = OpenAIModel(model_name="gpt-3.5-turbo") # Initialize with a specific provider # model = OpenAIModel(model_name="gpt-4", provider="openai-api") ```