{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "538a3f0c-50c1-4952-9fcc-070d365c9a0f", "metadata": { "scrolled": true }, "outputs": [], "source": [ "import os\n", "import subprocess\n", "from threading import Timer\n", "from queue import Queue\n", "\n", "ROOT_DIR = \"/content\"\n", "REPO_URL = \"https://huggingface.co/spaces/artificialguybr/PonyDiffusion-XL-Free-DEMO/new/main"\n", "REPO_DIR = os.path.join(ROOT_DIR, \"cagliostro-webui\")\n", "NGROK_TOKEN = \"\"\n", "\n", "os.environ[\"HF_TOKEN\"] = \"\"\n", "os.environ[\"IS_COLAB\"] = \"1\"\n", "os.environ[\"MODEL\"] = \"https://huggingface.co/AstraliteHeart/pony-diffusion-v6/blob/main/v6.safetensors\"\n", "os.environ[\"CACHE_EXAMPLES\"] = \"1\"\n", "\n", "def clone(url, dir, branch=None):\n", " subprocess.run([\"git\", \"clone\", url, dir], check=True)\n", " if branch:\n", " subprocess.run([\"git\", \"checkout\", branch], cwd=dir, check=True)\n", "\n", "def install_deps(dir):\n", " subprocess.run([\"pip\", \"install\", \"-r\", \"requirements.txt\"], cwd=dir, check=True)\n", "\n", "def ngrok_tunnel(port,queue,auth_token):\n", " ngrok.set_auth_token(auth_token)\n", " url = ngrok.connect(port)\n", " queue.put(url)\n", "\n", "def main():\n", " if not os.path.exists(REPO_DIR):\n", " print(f\"Cloning Repository to {REPO_DIR}\")\n", " clone(REPO_URL, REPO_DIR)\n", " print(f\"Installing required python libraries\")\n", " install_deps(REPO_DIR)\n", " print(\"Done!\")\n", "\n", " os.chdir(REPO_DIR)\n", " \n", " if NGROK_TOKEN:\n", " try:\n", " from pyngrok import conf,ngrok\n", " except:\n", " !pip install -qqqq --upgrade setuptools\n", " !pip install -qqqq -U pyngrok\n", " from pyngrok import conf,ngrok\n", " \n", " ngrok_output_queue = Queue()\n", " ngrok_thread = Timer(2, ngrok_tunnel, args=(7860, ngrok_output_queue, NGROK_TOKEN))\n", " ngrok_thread.start()\n", " ngrok_thread.join()\n", " \n", " print(ngrok_output_queue.get()) \n", " \n", " !python app.py\n", "\n", "if __name__ == \"__main__\":\n", " main()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.12" } }, "nbformat": 4, "nbformat_minor": 5 }