{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "provenance": [],
      "machine_shape": "hm",
      "gpuType": "L4"
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    },
    "language_info": {
      "name": "python"
    },
    "accelerator": "GPU"
  },
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "---\n",
        "\n",
        "📌 **This notebook has been updated [here](https://github.com/jhj0517/MusePose-WebUI)!**\n",
        "\n",
        "🖋 **Author**: [jhj0517](https://github.com/jhj0517/MusePose-WebUI/blob/main/notebook/musepose_webui.ipynb)\n",
        "\n",
        "😎 **Support the Project**:\n",
        "\n",
        "If you find this project useful, please consider supporting it:\n",
        "\n",
        "<a href=\"https://ko-fi.com/A0A7JSQRJ\" target=\"_blank\">\n",
        "    <img src=\"https://storage.ko-fi.com/cdn/kofi2.png?v=3\" alt=\"Buy Me a Coffee at ko-fi.com\" height=\"36\">\n",
        "</a>\n",
        "\n",
        "---"
      ],
      "metadata": {
        "id": "zW0EANufPvGU"
      }
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "cellView": "form",
        "id": "cX7SwywlzrS4"
      },
      "outputs": [],
      "source": [
        "#@title #Installation\n",
        "#@markdown This will install dependencies for musepose webui. Ignore \"RESTART SESSION\" warning if it appears\n",
        "\n",
        "!git clone https://github.com/jhj0517/MusePose-WebUI.git\n",
        "%cd MusePose-WebUI\n",
        "!pip install -r requirements.txt\n"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "#@title #Mount Google Drive\n",
        "#@markdown Mount Your Google Drive for your model & output paths.\n",
        "\n",
        "# Mount Google Drive\n",
        "from google.colab import drive\n",
        "import os\n",
        "drive.mount('/content/drive')"
      ],
      "metadata": {
        "cellView": "form",
        "id": "IbkdctzO0S2n"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "#@title # Enter Your Paths on Google Drive\n",
        "#@markdown Enter your models & output directory paths on your google drive.\n",
        "\n",
        "#@markdown  Remove these default values below and enter yours.\n",
        "\n",
        "MusePose_Model_Path = '/content/drive/MyDrive/MusePose/pretrained_weights' # @param {type:\"string\"}\n",
        "Output_Dir = '/content/drive/MyDrive/MusePose/output_folder'  # @param {type:\"string\"}\n",
        "\n",
        "#@markdown You should prepare folder like `Your_MusePose_Models` folder with the following structure on your Google Drive:\n",
        "#@markdown ```\n",
        "#@markdown ./Your_MusePose_Models/\n",
        "#@markdown |-- MusePose\n",
        "#@markdown |   |-- denoising_unet.pth\n",
        "#@markdown |   |-- motion_module.pth\n",
        "#@markdown |   |-- pose_guider.pth\n",
        "#@markdown |   â””-- reference_unet.pth\n",
        "#@markdown |-- dwpose\n",
        "#@markdown |   |-- dw-ll_ucoco_384.pth\n",
        "#@markdown |   └── yolox_l_8x8_300e_coco.pth\n",
        "#@markdown |-- sd-image-variations-diffusers\n",
        "#@markdown |   └── unet\n",
        "#@markdown |       |-- config.json\n",
        "#@markdown |       â””-- diffusion_pytorch_model.bin\n",
        "#@markdown |-- image_encoder\n",
        "#@markdown |   |-- config.json\n",
        "#@markdown |   â””-- pytorch_model.bin\n",
        "#@markdown â””-- sd-vae-ft-mse\n",
        "#@markdown     |-- config.json\n",
        "#@markdown     â””-- diffusion_pytorch_model.bin\n",
        "#@markdown ```\n",
        "\n",
        "#@markdown You can download weigths here: [ReadMe](https://github.com/TMElyralab/MusePose?tab=readme-ov-file#download-weights)\n",
        "\n",
        "\n",
        "\n",
        "# Symlink model path with google drive and local\n",
        "local_model_path = '/content/MusePose-WebUI/pretrained_weights'\n",
        "os.makedirs(local_model_path, exist_ok=True)\n",
        "\n",
        "for item in os.listdir(MusePose_Model_Path):\n",
        "    item_path = os.path.join(MusePose_Model_Path, item)\n",
        "    symlink_path = os.path.join(local_model_path, item)\n",
        "    os.symlink(item_path, symlink_path)\n",
        "!ls \"$local_model_path\"\n",
        "\n",
        "# Symlink output path with google drive and local\n",
        "local_output_path = '/content/MusePose-WebUI/outputs'\n",
        "os.makedirs(local_output_path, exist_ok=True)\n",
        "\n",
        "if os.path.exists(local_output_path):\n",
        "    !rm -r \"$local_output_path\"\n",
        "\n",
        "os.symlink(Output_Dir, local_output_path)\n",
        "!ls \"$local_output_path\""
      ],
      "metadata": {
        "cellView": "form",
        "id": "FILfLli5MdRk"
      },
      "execution_count": null,
      "outputs": []
    },
    {
      "cell_type": "code",
      "source": [
        "#@title # Run Web UI\n",
        "#@markdown Now you can run the MusePose webui, Use public URL that is displayed\n",
        "\n",
        "!python app.py --share"
      ],
      "metadata": {
        "id": "OXoOcH7n05lo",
        "cellView": "form"
      },
      "execution_count": null,
      "outputs": []
    }
  ]
}