Spaces:
Running
on
Zero
Running
on
Zero
artificialguybr
commited on
Commit
•
1ba4b19
1
Parent(s):
01d1cce
Create demo.ipynb
Browse files- demo.ipynb +93 -0
demo.ipynb
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": null,
|
6 |
+
"id": "538a3f0c-50c1-4952-9fcc-070d365c9a0f",
|
7 |
+
"metadata": {
|
8 |
+
"scrolled": true
|
9 |
+
},
|
10 |
+
"outputs": [],
|
11 |
+
"source": [
|
12 |
+
"import os\n",
|
13 |
+
"import subprocess\n",
|
14 |
+
"from threading import Timer\n",
|
15 |
+
"from queue import Queue\n",
|
16 |
+
"\n",
|
17 |
+
"ROOT_DIR = \"/content\"\n",
|
18 |
+
"REPO_URL = \"https://huggingface.co/spaces/artificialguybr/PonyDiffusion-XL-Free-DEMO/new/main"\n",
|
19 |
+
"REPO_DIR = os.path.join(ROOT_DIR, \"cagliostro-webui\")\n",
|
20 |
+
"NGROK_TOKEN = \"\"\n",
|
21 |
+
"\n",
|
22 |
+
"os.environ[\"HF_TOKEN\"] = \"\"\n",
|
23 |
+
"os.environ[\"IS_COLAB\"] = \"1\"\n",
|
24 |
+
"os.environ[\"MODEL\"] = \"https://huggingface.co/AstraliteHeart/pony-diffusion-v6/blob/main/v6.safetensors\"\n",
|
25 |
+
"os.environ[\"CACHE_EXAMPLES\"] = \"1\"\n",
|
26 |
+
"\n",
|
27 |
+
"def clone(url, dir, branch=None):\n",
|
28 |
+
" subprocess.run([\"git\", \"clone\", url, dir], check=True)\n",
|
29 |
+
" if branch:\n",
|
30 |
+
" subprocess.run([\"git\", \"checkout\", branch], cwd=dir, check=True)\n",
|
31 |
+
"\n",
|
32 |
+
"def install_deps(dir):\n",
|
33 |
+
" subprocess.run([\"pip\", \"install\", \"-r\", \"requirements.txt\"], cwd=dir, check=True)\n",
|
34 |
+
"\n",
|
35 |
+
"def ngrok_tunnel(port,queue,auth_token):\n",
|
36 |
+
" ngrok.set_auth_token(auth_token)\n",
|
37 |
+
" url = ngrok.connect(port)\n",
|
38 |
+
" queue.put(url)\n",
|
39 |
+
"\n",
|
40 |
+
"def main():\n",
|
41 |
+
" if not os.path.exists(REPO_DIR):\n",
|
42 |
+
" print(f\"Cloning Repository to {REPO_DIR}\")\n",
|
43 |
+
" clone(REPO_URL, REPO_DIR)\n",
|
44 |
+
" print(f\"Installing required python libraries\")\n",
|
45 |
+
" install_deps(REPO_DIR)\n",
|
46 |
+
" print(\"Done!\")\n",
|
47 |
+
"\n",
|
48 |
+
" os.chdir(REPO_DIR)\n",
|
49 |
+
" \n",
|
50 |
+
" if NGROK_TOKEN:\n",
|
51 |
+
" try:\n",
|
52 |
+
" from pyngrok import conf,ngrok\n",
|
53 |
+
" except:\n",
|
54 |
+
" !pip install -qqqq --upgrade setuptools\n",
|
55 |
+
" !pip install -qqqq -U pyngrok\n",
|
56 |
+
" from pyngrok import conf,ngrok\n",
|
57 |
+
" \n",
|
58 |
+
" ngrok_output_queue = Queue()\n",
|
59 |
+
" ngrok_thread = Timer(2, ngrok_tunnel, args=(7860, ngrok_output_queue, NGROK_TOKEN))\n",
|
60 |
+
" ngrok_thread.start()\n",
|
61 |
+
" ngrok_thread.join()\n",
|
62 |
+
" \n",
|
63 |
+
" print(ngrok_output_queue.get()) \n",
|
64 |
+
" \n",
|
65 |
+
" !python app.py\n",
|
66 |
+
"\n",
|
67 |
+
"if __name__ == \"__main__\":\n",
|
68 |
+
" main()"
|
69 |
+
]
|
70 |
+
}
|
71 |
+
],
|
72 |
+
"metadata": {
|
73 |
+
"kernelspec": {
|
74 |
+
"display_name": "Python 3 (ipykernel)",
|
75 |
+
"language": "python",
|
76 |
+
"name": "python3"
|
77 |
+
},
|
78 |
+
"language_info": {
|
79 |
+
"codemirror_mode": {
|
80 |
+
"name": "ipython",
|
81 |
+
"version": 3
|
82 |
+
},
|
83 |
+
"file_extension": ".py",
|
84 |
+
"mimetype": "text/x-python",
|
85 |
+
"name": "python",
|
86 |
+
"nbconvert_exporter": "python",
|
87 |
+
"pygments_lexer": "ipython3",
|
88 |
+
"version": "3.10.12"
|
89 |
+
}
|
90 |
+
},
|
91 |
+
"nbformat": 4,
|
92 |
+
"nbformat_minor": 5
|
93 |
+
}
|