Spaces:
Sleeping
Sleeping
Akimitsujiro
commited on
Commit
•
b6737a0
1
Parent(s):
ad61ba2
Delete demo.ipynb
Browse files- demo.ipynb +0 -114
demo.ipynb
DELETED
@@ -1,114 +0,0 @@
|
|
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 |
-
"id": "538a3f0c-50c1-4952-9fcc-070d365c9a0f"
|
10 |
-
},
|
11 |
-
"outputs": [],
|
12 |
-
"source": [
|
13 |
-
"import os\n",
|
14 |
-
"import subprocess\n",
|
15 |
-
"from threading import Timer\n",
|
16 |
-
"from queue import Queue\n",
|
17 |
-
"\n",
|
18 |
-
"def is_colab():\n",
|
19 |
-
" try:\n",
|
20 |
-
" import google.colab\n",
|
21 |
-
" return True\n",
|
22 |
-
" except ImportError:\n",
|
23 |
-
" return False\n",
|
24 |
-
"\n",
|
25 |
-
"ROOT_DIR = \"/workspace/\" if not is_colab() else \"/content/\"\n",
|
26 |
-
"REPO_URL = \"https://huggingface.co/spaces/Linaqruf/animagine-xl\"\n",
|
27 |
-
"REPO_DIR = os.path.join(ROOT_DIR, \"animagine-xl\")\n",
|
28 |
-
"\n",
|
29 |
-
"NGROK_TOKEN = \"\"\n",
|
30 |
-
"NGROK_SUBDOMAIN = \"\"\n",
|
31 |
-
"PORT = 7860\n",
|
32 |
-
"\n",
|
33 |
-
"# os.environ[\"HF_TOKEN\"] = \"\"\n",
|
34 |
-
"os.environ[\"IS_COLAB\"] = \"1\"\n",
|
35 |
-
"os.environ[\"MODEL\"] = \"https://huggingface.co/cagliostrolab/animagine-xl-3.0/blob/main/animagine-xl-3.0.safetensors\"\n",
|
36 |
-
"os.environ[\"CACHE_EXAMPLES\"] = \"1\"\n",
|
37 |
-
"\n",
|
38 |
-
"def clone_repository(url, directory, branch=None):\n",
|
39 |
-
" subprocess.run([\"git\", \"clone\", url, directory], check=True)\n",
|
40 |
-
" if branch:\n",
|
41 |
-
" subprocess.run([\"git\", \"checkout\", branch], cwd=directory, check=True)\n",
|
42 |
-
"\n",
|
43 |
-
"def install_dependencies(directory):\n",
|
44 |
-
" dependencies = [\"accelerate==0.27.2\", \"diffusers==0.26.3\", \"gradio==4.20.0\",\n",
|
45 |
-
" \"invisible-watermark==0.2.0\", \"spaces==0.24.0\", \"omegaconf==2.3.0\", \"timm==0.9.10\"]\n",
|
46 |
-
" if is_colab():\n",
|
47 |
-
" subprocess.run([\"pip\", \"install\"] + dependencies, check=True)\n",
|
48 |
-
" else:\n",
|
49 |
-
" requirements_path = os.path.join(directory, \"requirements.txt\")\n",
|
50 |
-
" subprocess.run([\"pip\", \"install\", \"-r\", requirements_path], check=True)\n",
|
51 |
-
"\n",
|
52 |
-
"def setup_ngrok_tunnel(port, queue, auth_token, subdomain):\n",
|
53 |
-
" ngrok.set_auth_token(auth_token)\n",
|
54 |
-
" url = ngrok.connect(port, bind_tls=True, subdomain=subdomain)\n",
|
55 |
-
" queue.put(url)\n",
|
56 |
-
"\n",
|
57 |
-
"def main():\n",
|
58 |
-
" if not os.path.exists(REPO_DIR):\n",
|
59 |
-
" print(f\"Cloning repository to {REPO_DIR}\")\n",
|
60 |
-
" clone_repository(REPO_URL, REPO_DIR)\n",
|
61 |
-
"\n",
|
62 |
-
" print(\"Installing required Python libraries\")\n",
|
63 |
-
" install_dependencies(REPO_DIR)\n",
|
64 |
-
" print(\"Done!\")\n",
|
65 |
-
"\n",
|
66 |
-
" os.chdir(REPO_DIR)\n",
|
67 |
-
"\n",
|
68 |
-
" if NGROK_TOKEN:\n",
|
69 |
-
" try:\n",
|
70 |
-
" from pyngrok import conf, ngrok\n",
|
71 |
-
" except ImportError:\n",
|
72 |
-
" subprocess.run([\"pip\", \"install\", \"-qqqq\", \"--upgrade\", \"setuptools\"], check=True)\n",
|
73 |
-
" subprocess.run([\"pip\", \"install\", \"-qqqq\", \"-U\", \"pyngrok\"], check=True)\n",
|
74 |
-
" from pyngrok import conf, ngrok\n",
|
75 |
-
"\n",
|
76 |
-
" ngrok.kill()\n",
|
77 |
-
" ngrok_output_queue = Queue()\n",
|
78 |
-
" ngrok_thread = Timer(2, setup_ngrok_tunnel, args=(PORT, ngrok_output_queue, NGROK_TOKEN, NGROK_SUBDOMAIN))\n",
|
79 |
-
" ngrok_thread.start()\n",
|
80 |
-
" ngrok_thread.join()\n",
|
81 |
-
" print(ngrok_output_queue.get())\n",
|
82 |
-
"\n",
|
83 |
-
" !python app.py\n",
|
84 |
-
"\n",
|
85 |
-
"if __name__ == \"__main__\":\n",
|
86 |
-
" main()"
|
87 |
-
]
|
88 |
-
}
|
89 |
-
],
|
90 |
-
"metadata": {
|
91 |
-
"kernelspec": {
|
92 |
-
"display_name": "Python 3 (ipykernel)",
|
93 |
-
"language": "python",
|
94 |
-
"name": "python3"
|
95 |
-
},
|
96 |
-
"language_info": {
|
97 |
-
"codemirror_mode": {
|
98 |
-
"name": "ipython",
|
99 |
-
"version": 3
|
100 |
-
},
|
101 |
-
"file_extension": ".py",
|
102 |
-
"mimetype": "text/x-python",
|
103 |
-
"name": "python",
|
104 |
-
"nbconvert_exporter": "python",
|
105 |
-
"pygments_lexer": "ipython3",
|
106 |
-
"version": "3.10.12"
|
107 |
-
},
|
108 |
-
"colab": {
|
109 |
-
"provenance": []
|
110 |
-
}
|
111 |
-
},
|
112 |
-
"nbformat": 4,
|
113 |
-
"nbformat_minor": 5
|
114 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|