Cagliostro commited on
Commit
19b5d32
1 Parent(s): e0b1273

Upload demo.ipynb

Browse files
Files changed (1) hide show
  1. demo.ipynb +45 -28
demo.ipynb CHANGED
@@ -14,55 +14,72 @@
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/Linaqruf/animagine-xl\"\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/cagliostrolab/animagine-xl-3.0/blob/main/animagine-xl-3.0.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()"
 
14
  "from threading import Timer\n",
15
  "from queue import Queue\n",
16
  "\n",
17
+ "def is_colab():\n",
18
+ " try:\n",
19
+ " import google.colab\n",
20
+ " return True\n",
21
+ " except ImportError:\n",
22
+ " return False\n",
23
+ " \n",
24
+ "ROOT_DIR = \"/workspace/\" if not is_colab() else \"/content/\"\n",
25
+ "REPO_URL = \"https://huggingface.co/spaces/cagliostrolab/animagine-xl-3.1\"\n",
26
+ "REPO_DIR = os.path.join(ROOT_DIR, \"animagine-xl\")\n",
27
+ "\n",
28
  "NGROK_TOKEN = \"\"\n",
29
+ "NGROK_SUBDOMAIN = \"\"\n",
30
+ "PORT = 7860\n",
31
  "\n",
32
+ "# os.environ[\"HF_TOKEN\"] = \"\"\n",
33
  "os.environ[\"IS_COLAB\"] = \"1\"\n",
34
+ "os.environ[\"MODEL\"] = \"https://huggingface.co/cagliostrolab/animagine-xl-3.1/blob/main/animagine-xl-3.1.safetensors\"\n",
35
  "os.environ[\"CACHE_EXAMPLES\"] = \"1\"\n",
36
  "\n",
37
+ "def clone_repository(url, directory, branch=None):\n",
38
+ " subprocess.run([\"git\", \"clone\", url, directory], check=True)\n",
39
  " if branch:\n",
40
+ " subprocess.run([\"git\", \"checkout\", branch], cwd=directory, check=True)\n",
41
  "\n",
42
+ "def install_dependencies(directory):\n",
43
+ " dependencies = [\"accelerate==0.27.2\", \"diffusers==0.26.3\", \"gradio==4.20.0\",\n",
44
+ " \"invisible-watermark==0.2.0\", \"spaces==0.24.0\", \"omegaconf==2.3.0\", \"timm==0.9.10\"]\n",
45
+ " if is_colab():\n",
46
+ " subprocess.run([\"pip\", \"install\"] + dependencies, check=True)\n",
47
+ " else:\n",
48
+ " requirements_path = os.path.join(directory, \"requirements.txt\")\n",
49
+ " subprocess.run([\"pip\", \"install\", \"-r\", requirements_path], check=True)\n",
50
  "\n",
51
+ "def setup_ngrok_tunnel(port, queue, auth_token, subdomain):\n",
52
  " ngrok.set_auth_token(auth_token)\n",
53
+ " url = ngrok.connect(port, bind_tls=True, subdomain=subdomain)\n",
54
  " queue.put(url)\n",
55
  "\n",
56
  "def main():\n",
57
  " if not os.path.exists(REPO_DIR):\n",
58
+ " print(f\"Cloning repository to {REPO_DIR}\")\n",
59
+ " clone_repository(REPO_URL, REPO_DIR)\n",
60
+ "\n",
61
+ " print(\"Installing required Python libraries\")\n",
62
+ " install_dependencies(REPO_DIR)\n",
63
  " print(\"Done!\")\n",
64
  "\n",
65
  " os.chdir(REPO_DIR)\n",
66
+ "\n",
67
  " if NGROK_TOKEN:\n",
68
  " try:\n",
69
+ " from pyngrok import conf, ngrok\n",
70
+ " except ImportError:\n",
71
+ " subprocess.run([\"pip\", \"install\", \"-qqqq\", \"--upgrade\", \"setuptools\"], check=True)\n",
72
+ " subprocess.run([\"pip\", \"install\", \"-qqqq\", \"-U\", \"pyngrok\"], check=True)\n",
73
+ " from pyngrok import conf, ngrok\n",
74
+ "\n",
75
+ " ngrok.kill()\n",
76
  " ngrok_output_queue = Queue()\n",
77
+ " ngrok_thread = Timer(2, setup_ngrok_tunnel, args=(PORT, ngrok_output_queue, NGROK_TOKEN, NGROK_SUBDOMAIN))\n",
78
  " ngrok_thread.start()\n",
79
  " ngrok_thread.join()\n",
80
+ " print(ngrok_output_queue.get())\n",
81
+ "\n",
82
+ " subprocess.run([\"python\", \"app.py\"], check=True)\n",
 
83
  "\n",
84
  "if __name__ == \"__main__\":\n",
85
  " main()"