File size: 2,901 Bytes
01699a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
{
 "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/RealVisXL-Free-DEMO/"\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/SG161222/RealVisXL_V4.0/blob/main/RealVisXL_V4.0.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
}