viyi commited on
Commit
d95d9a4
·
verified ·
1 Parent(s): 07350d1

Upload sdwui-start-util.dev.ipynb

Browse files
Files changed (1) hide show
  1. sdwui-start-util.dev.ipynb +154 -66
sdwui-start-util.dev.ipynb CHANGED
@@ -140,72 +140,6 @@
140
  "_config_args:dict[str, str] = locals().get('config_args') or globals().get('config_args') or {}"
141
  ]
142
  },
143
- {
144
- "cell_type": "code",
145
- "execution_count": null,
146
- "metadata": {},
147
- "outputs": [],
148
- "source": [
149
- "def _init_conf():\n",
150
- " global _useFrpc\n",
151
- " global _useNgrok\n",
152
- " global _reLoad\n",
153
- " global _before_downloading\n",
154
- " global _async_downloading\n",
155
- " global _before_start_sync_downloading\n",
156
- " global _server_port\n",
157
- " global _sd_git_repo\n",
158
- " global _sd_config_git_repu\n",
159
- " global _huggingface_token\n",
160
- " global _huggingface_repo\n",
161
- " global _link_instead_of_copy\n",
162
- " global show_shell_info\n",
163
- " global _multi_case\n",
164
- " global _skip_start\n",
165
- " global _on_before_start\n",
166
- " global _skip_webui\n",
167
- " global _proxy_path\n",
168
- " global _sub_path\n",
169
- " global _config_args\n",
170
- " \n",
171
- " _useFrpc = locals().get('useFrpc') or globals().get('useFrpc') or True\n",
172
- " _useNgrok = locals().get('useNgrok') or globals().get('useNgrok') or True\n",
173
- " _reLoad = locals().get('reLoad') or globals().get('reLoad') or False\n",
174
- " _before_downloading = locals().get('before_downloading') or globals().get('before_downloading') or ''\n",
175
- " _async_downloading = locals().get('async_downloading') or globals().get('async_downloading') or ''\n",
176
- " _before_start_sync_downloading = locals().get('before_start_sync_downloading') or globals().get('before_start_sync_downloading') or ''\n",
177
- " _server_port = locals().get('server_port') or globals().get('server_port') or 7860\n",
178
- " _sd_git_repo = locals().get('sd_git_repo') or globals().get('sd_git_repo') or 'https://github.com/viyiviyi/stable-diffusion-webui.git -b local' \n",
179
- " _sd_git_repo = _sd_git_repo\\\n",
180
- " .replace('{sdwui}','stable-diffusion-webui')\\\n",
181
- " .replace('{wui}',\"webui\") \n",
182
- " _sd_config_git_repu = locals().get('sd_config_git_repu') or globals().get('sd_config_git_repu') or 'https://github.com/viyiviyi/sd-configs.git'\n",
183
- " _sd_config_git_repu = _sd_config_git_repu\\\n",
184
- " .replace('{sdwui}','stable-diffusion-webui')\\\n",
185
- " .replace('{wui}',\"webui\")\n",
186
- " _huggingface_token = locals().get('huggingface_token') or globals().get('huggingface_token') or '{input_path}/configs/huggingface_token.txt'\n",
187
- " _huggingface_token = _huggingface_token\\\n",
188
- " .replace('{sdwui}','stable-diffusion-webui')\\\n",
189
- " .replace('{wui}',\"webui\")\n",
190
- " _huggingface_repo = locals().get('huggingface_repo') or globals().get('huggingface_repo') or ''\n",
191
- " _huggingface_repo = _huggingface_repo\\\n",
192
- " .replace('{sdwui}','stable-diffusion-webui')\\\n",
193
- " .replace('{wui}',\"webui\")\n",
194
- " _link_instead_of_copy = locals().get('link_instead_of_copy') or globals().get('link_instead_of_copy') or True\n",
195
- " show_shell_info = locals().get('hidden_console_info') or globals().get('hidden_console_info')\n",
196
- " if show_shell_info is None: show_shell_info = False\n",
197
- " _multi_case = locals().get('multi_case') or globals().get('multi_case') or False\n",
198
- " _skip_start = locals().get('skip_start') or globals().get('skip_start') or True\n",
199
- " _on_before_start = locals().get('on_before_start') or globals().get('on_before_start') or before_start \n",
200
- " _skip_webui = locals().get('skip_webui') or globals().get('skip_webui') or False\n",
201
- " _proxy_path = locals().get('proxy_path') or globals().get('proxy_path') or {}\n",
202
- " _sub_path = locals().get('sub_path') or globals().get('sub_path') or ['/','/1/']\n",
203
- " if len(_sub_path) != 2:\n",
204
- " _sub_path = ['/','/1/']\n",
205
- " \n",
206
- " _config_args = locals().get('config_args') or globals().get('config_args') or {}"
207
- ]
208
- },
209
  {
210
  "cell_type": "code",
211
  "execution_count": null,
@@ -370,6 +304,7 @@
370
  "space_string = ' \\n\\r\\t\\'\\\",'\n",
371
  "\n",
372
  "def config_reader(conf:str):\n",
 
373
  " args = [replace_path(item.split('#')[0].strip(space_string)) for item in conf.split('\\n') if item.strip(space_string)]\n",
374
  " return [item.strip() for item in args if item.strip()]\n"
375
  ]
@@ -470,6 +405,159 @@
470
  "huggingface_headers:dict = None "
471
  ]
472
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
473
  {
474
  "cell_type": "markdown",
475
  "metadata": {},
 
140
  "_config_args:dict[str, str] = locals().get('config_args') or globals().get('config_args') or {}"
141
  ]
142
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143
  {
144
  "cell_type": "code",
145
  "execution_count": null,
 
304
  "space_string = ' \\n\\r\\t\\'\\\",'\n",
305
  "\n",
306
  "def config_reader(conf:str):\n",
307
+ " conf = conf or \"\"\n",
308
  " args = [replace_path(item.split('#')[0].strip(space_string)) for item in conf.split('\\n') if item.strip(space_string)]\n",
309
  " return [item.strip() for item in args if item.strip()]\n"
310
  ]
 
405
  "huggingface_headers:dict = None "
406
  ]
407
  },
408
+ {
409
+ "cell_type": "code",
410
+ "execution_count": null,
411
+ "metadata": {},
412
+ "outputs": [],
413
+ "source": [
414
+ "def _init_conf():\n",
415
+ " global _useFrpc\n",
416
+ " global _useNgrok\n",
417
+ " global _reLoad\n",
418
+ " global _before_downloading\n",
419
+ " global _async_downloading\n",
420
+ " global _before_start_sync_downloading\n",
421
+ " global _server_port\n",
422
+ " global _sd_git_repo\n",
423
+ " global _sd_config_git_repu\n",
424
+ " global _huggingface_token\n",
425
+ " global _huggingface_repo\n",
426
+ " global _link_instead_of_copy\n",
427
+ " global show_shell_info\n",
428
+ " global _multi_case\n",
429
+ " global _skip_start\n",
430
+ " global _on_before_start\n",
431
+ " global _skip_webui\n",
432
+ " global _proxy_path\n",
433
+ " global _sub_path\n",
434
+ " global _config_args\n",
435
+ " global _install_path\n",
436
+ " global _output_path\n",
437
+ " global _input_path\n",
438
+ " global _ui_dir_name\n",
439
+ " \n",
440
+ " global ngrokTokenFile\n",
441
+ " global frpcConfigFile\n",
442
+ " global frpcSSLFFlies\n",
443
+ " global frpcExePath\n",
444
+ " global otherArgs\n",
445
+ " global _setting_file\n",
446
+ " global _ui_config_file\n",
447
+ " global _frp_temp_config_file\n",
448
+ " global _frp_config_or_file\n",
449
+ " global ngrokToken\n",
450
+ " global venvPath\n",
451
+ " \n",
452
+ " _useFrpc = locals().get('useFrpc') or globals().get('useFrpc') or True\n",
453
+ " _useNgrok = locals().get('useNgrok') or globals().get('useNgrok') or True\n",
454
+ " _reLoad = locals().get('reLoad') or globals().get('reLoad') or False\n",
455
+ " _before_downloading = locals().get('before_downloading') or globals().get('before_downloading') or ''\n",
456
+ " _async_downloading = locals().get('async_downloading') or globals().get('async_downloading') or ''\n",
457
+ " _before_start_sync_downloading = locals().get('before_start_sync_downloading') or globals().get('before_start_sync_downloading') or ''\n",
458
+ " _server_port = locals().get('server_port') or globals().get('server_port') or 7860\n",
459
+ " _sd_git_repo = locals().get('sd_git_repo') or globals().get('sd_git_repo') or 'https://github.com/viyiviyi/stable-diffusion-webui.git -b local' \n",
460
+ " _sd_git_repo = _sd_git_repo\\\n",
461
+ " .replace('{sdwui}','stable-diffusion-webui')\\\n",
462
+ " .replace('{wui}',\"webui\") \n",
463
+ " _sd_config_git_repu = locals().get('sd_config_git_repu') or globals().get('sd_config_git_repu') or 'https://github.com/viyiviyi/sd-configs.git'\n",
464
+ " _sd_config_git_repu = _sd_config_git_repu\\\n",
465
+ " .replace('{sdwui}','stable-diffusion-webui')\\\n",
466
+ " .replace('{wui}',\"webui\")\n",
467
+ " _huggingface_token = locals().get('huggingface_token') or globals().get('huggingface_token') or '{input_path}/configs/huggingface_token.txt'\n",
468
+ " _huggingface_token = _huggingface_token\\\n",
469
+ " .replace('{sdwui}','stable-diffusion-webui')\\\n",
470
+ " .replace('{wui}',\"webui\")\n",
471
+ " _huggingface_repo = locals().get('huggingface_repo') or globals().get('huggingface_repo') or ''\n",
472
+ " _huggingface_repo = _huggingface_repo\\\n",
473
+ " .replace('{sdwui}','stable-diffusion-webui')\\\n",
474
+ " .replace('{wui}',\"webui\")\n",
475
+ " _link_instead_of_copy = locals().get('link_instead_of_copy') or globals().get('link_instead_of_copy') or True\n",
476
+ " show_shell_info = locals().get('hidden_console_info') or globals().get('hidden_console_info')\n",
477
+ " if show_shell_info is None: show_shell_info = False\n",
478
+ " _multi_case = locals().get('multi_case') or globals().get('multi_case') or False\n",
479
+ " _skip_start = locals().get('skip_start') or globals().get('skip_start') or True\n",
480
+ " _on_before_start = locals().get('on_before_start') or globals().get('on_before_start') or before_start \n",
481
+ " _skip_webui = locals().get('skip_webui') or globals().get('skip_webui') or False\n",
482
+ " _proxy_path = locals().get('proxy_path') or globals().get('proxy_path') or {}\n",
483
+ " _sub_path = locals().get('sub_path') or globals().get('sub_path') or ['/','/1/']\n",
484
+ " if len(_sub_path) != 2:\n",
485
+ " _sub_path = ['/','/1/']\n",
486
+ " \n",
487
+ " _config_args = locals().get('config_args') or globals().get('config_args') or {}\n",
488
+ " \n",
489
+ " _install_path = locals().get('install_path') or globals().get('install_path') or _install_path\n",
490
+ " _output_path = locals().get('output_path') or globals().get('output_path') or _output_path\n",
491
+ " _input_path = locals().get('input_path') or globals().get('input_path') or _input_path\n",
492
+ " _ui_dir_name = locals().get('ui_dir_name') or globals().get('ui_dir_name') or _ui_dir_name\n",
493
+ " \n",
494
+ " ngrokTokenFile = os.path.join(_input_path,'configs/ngrok_token.txt') # 非必填 存放ngrokToken的文件的路径\n",
495
+ " frpcConfigFile = os.path.join(_input_path,'configs/frpc_koishi.ini') # 非必填 frp 配置文件\n",
496
+ " # ss证书目录 下载nginx的版本,把pem格式改成crt格式\n",
497
+ " frpcSSLFFlies = [os.path.join(_input_path,'configs/koishi_ssl')]\n",
498
+ " if 'frp_ssl_dir' in locals() or 'frp_ssl_dir' in globals():\n",
499
+ " frpcSSLFFlies = frpcSSLFFlies + config_reader(locals().get('frp_ssl_dir') or globals().get('frp_ssl_dir'))\n",
500
+ " # frpc 文件目录 如果目录不存在,会自动下载,也可以在数据集搜索 viyiviyi/utils 添加\n",
501
+ " frpcExePath = os.path.join(_input_path,'utils-tools/frpc')\n",
502
+ " # 其他需要加载的webui启动参数 写到【参数列表】这个配置去\n",
503
+ " otherArgs = '--xformers'\n",
504
+ " if 'sd_start_args' in locals() or 'sd_start_args' in globals():\n",
505
+ " otherArgs = ' '.join([item for item in config_reader(locals().get('sd_start_args') or globals().get('sd_start_args')) if item != '--no-gradio-queue'])\n",
506
+ "\n",
507
+ " # 这下面的是用于初始化一些值或者环境变量的,轻易别改\n",
508
+ " _setting_file = replace_path(locals().get('setting_file') or globals().get('setting_file') or 'config.json')\n",
509
+ "\n",
510
+ " _ui_config_file = replace_path(locals().get('ui_config_file') or globals().get('ui_config_file') or 'ui-config.json')\n",
511
+ "\n",
512
+ " # 设置文件路径\n",
513
+ " if Path(f\"{os.environ['HOME']}/google_drive/MyDrive\").exists():\n",
514
+ " if _setting_file == '/kaggle/working/configs/config.json':\n",
515
+ " _setting_file = os.path.join(_output_path,'configs/config.json')\n",
516
+ " if _ui_config_file == '/kaggle/working/configs/ui-config.json':\n",
517
+ " _ui_config_file = os.path.join(_output_path,'configs/ui-config.json')\n",
518
+ " \n",
519
+ " frpcStartArg = ''\n",
520
+ " freefrp_url = ''\n",
521
+ " _frp_temp_config_file = ''\n",
522
+ " _frp_config_or_file = replace_path(locals().get('frp_config_or_file') or globals().get('frp_config_or_file')) or frpcConfigFile\n",
523
+ " run(f'''mkdir -p {_install_path}/configFiles''')\n",
524
+ " if _frp_config_or_file:\n",
525
+ " if '[common]' in _frp_config_or_file:\n",
526
+ " echoToFile(_frp_config_or_file,f'{_install_path}/configFiles/temp_frpc_webui.ini')\n",
527
+ " _frp_temp_config_file = f'{_install_path}/configFiles/temp_frpc_webui.ini'\n",
528
+ " elif '.ini' in _frp_config_or_file:\n",
529
+ " _frp_temp_config_file = _frp_config_or_file.strip()\n",
530
+ " \n",
531
+ " if _frp_temp_config_file:\n",
532
+ " if Path(_frp_temp_config_file).exists():\n",
533
+ " run(f'''cp -f {_frp_temp_config_file} {_install_path}/configFiles/frpc_webui.ini''')\n",
534
+ " run(f'''sed -i \"s/local_port = .*/local_port = {_server_port}/g\" {_install_path}/configFiles/frpc_webui.ini''')\n",
535
+ " frpcStartArg = f' -c {_install_path}/configFiles/frpc_webui.ini'\n",
536
+ " elif _frp_config_or_file.strip().startswith('-f'):\n",
537
+ " frpcStartArg = _frp_config_or_file.strip()\n",
538
+ " \n",
539
+ " if not frpcStartArg:\n",
540
+ " conf,url = get_freefrp_confog(_server_port)\n",
541
+ " echoToFile(conf,f'{_install_path}/configFiles/frpc_webui.ini')\n",
542
+ " freefrp_url = url\n",
543
+ " frpcStartArg = f' -c {_install_path}/configFiles/frpc_webui.ini'\n",
544
+ "\n",
545
+ " ngrokToken=''\n",
546
+ " _ngrok_config_or_file = replace_path(locals().get('ngrok_config_or_file') or globals().get('ngrok_config_or_file')) or ngrokTokenFile\n",
547
+ " if _ngrok_config_or_file:\n",
548
+ " if Path(_ngrok_config_or_file.strip()).exists():\n",
549
+ " ngrokTokenFile = _ngrok_config_or_file.strip()\n",
550
+ " if Path(ngrokTokenFile).exists():\n",
551
+ " with open(ngrokTokenFile,encoding = \"utf-8\") as nkfile:\n",
552
+ " ngrokToken = nkfile.readline()\n",
553
+ " elif not _ngrok_config_or_file.strip().startswith('/'):\n",
554
+ " ngrokToken=_ngrok_config_or_file.strip()\n",
555
+ " \n",
556
+ " if not Path(venvPath).exists():\n",
557
+ " venvPath = os.path.join(_input_path,'sd-webui-venv/venv.zip')\n",
558
+ " "
559
+ ]
560
+ },
561
  {
562
  "cell_type": "markdown",
563
  "metadata": {},