Update SW_run.py
Browse files
SW_run.py
CHANGED
|
@@ -1,70 +1,73 @@
|
|
| 1 |
-
import subprocess
|
| 2 |
-
import sys
|
| 3 |
-
import logging
|
| 4 |
import os
|
| 5 |
-
import
|
| 6 |
-
import
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
#
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
os.remove(log_file)
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
|
| 15 |
-
if
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
# 配置日志
|
| 19 |
-
logging.basicConfig(filename=log_file, level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
| 20 |
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
logging.getLogger().addHandler(console_handler)
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
sys.stderr = logging.getLogger().handlers[0].stream
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
|
|
|
| 34 |
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
|
| 40 |
-
|
|
|
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
# 查找行中的 URL 地址并将匹配的行转换为十六进制后写入 url.txt
|
| 49 |
-
urls = url_pattern.findall(line)
|
| 50 |
-
if urls:
|
| 51 |
-
for url in urls:
|
| 52 |
-
hex_url = binascii.hexlify(url.encode()).decode()
|
| 53 |
-
url_file_handle.write(hex_url + '\n')
|
| 54 |
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
log_file_handle.flush()
|
| 58 |
|
| 59 |
-
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
logging.exception(f"程序发生异常: {e}")
|
| 64 |
-
except Exception as e:
|
| 65 |
-
# 捕获其他异常并记录到日志文件
|
| 66 |
-
logging.exception(f"程序发生异常: {e}")
|
| 67 |
-
finally:
|
| 68 |
-
# 最后,关闭日志处理程序,以确保所有日志都被写入到日志文件
|
| 69 |
-
logging.getLogger().removeHandler(console_handler)
|
| 70 |
-
console_handler.close()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
from modules import launch_utils
|
| 4 |
+
import pyngrok
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
|
| 8 |
+
#ngrok穿透
|
| 9 |
+
ngrok_use = True
|
| 10 |
+
ngrokTokenFile='/bushu/Authtoken.txt' # 非必填 存放ngrokToken的文件的路径
|
|
|
|
| 11 |
|
| 12 |
+
#ngrok
|
| 13 |
+
def ngrok_start(ngrokTokenFile: str, port: int, address_name: str, should_run: bool):
|
| 14 |
+
if not should_run:
|
| 15 |
+
print('Skipping ngrok start')
|
| 16 |
+
return
|
| 17 |
+
if Path(ngrokTokenFile).exists():
|
| 18 |
+
with open(ngrokTokenFile, encoding="utf-8") as nkfile:
|
| 19 |
+
ngrokToken = nkfile.readline()
|
| 20 |
+
print('use nrgok')
|
| 21 |
+
from pyngrok import conf, ngrok
|
| 22 |
+
conf.get_default().auth_token = ngrokToken
|
| 23 |
+
conf.get_default().monitor_thread = False
|
| 24 |
+
ssh_tunnels = ngrok.get_tunnels(conf.get_default())
|
| 25 |
+
if len(ssh_tunnels) == 0:
|
| 26 |
+
ssh_tunnel = ngrok.connect(port, bind_tls=True)
|
| 27 |
+
print(f'{address_name}:' + ssh_tunnel.public_url)
|
| 28 |
+
else:
|
| 29 |
+
print(f'{address_name}:' + ssh_tunnels[0].public_url)
|
| 30 |
+
else:
|
| 31 |
+
print('skip start ngrok')
|
| 32 |
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
args = launch_utils.args
|
| 35 |
+
python = launch_utils.python
|
| 36 |
+
git = launch_utils.git
|
| 37 |
+
index_url = launch_utils.index_url
|
| 38 |
+
dir_repos = launch_utils.dir_repos
|
|
|
|
| 39 |
|
| 40 |
+
commit_hash = launch_utils.commit_hash
|
| 41 |
+
git_tag = launch_utils.git_tag
|
|
|
|
| 42 |
|
| 43 |
+
run = launch_utils.run
|
| 44 |
+
is_installed = launch_utils.is_installed
|
| 45 |
+
repo_dir = launch_utils.repo_dir
|
| 46 |
|
| 47 |
+
run_pip = launch_utils.run_pip
|
| 48 |
+
check_run_python = launch_utils.check_run_python
|
| 49 |
+
git_clone = launch_utils.git_clone
|
| 50 |
+
git_pull_recursive = launch_utils.git_pull_recursive
|
| 51 |
+
list_extensions = launch_utils.list_extensions
|
| 52 |
+
run_extension_installer = launch_utils.run_extension_installer
|
| 53 |
+
prepare_environment = launch_utils.prepare_environment
|
| 54 |
+
configure_for_tests = launch_utils.configure_for_tests
|
| 55 |
+
start = launch_utils.start
|
| 56 |
|
| 57 |
+
def run_command(command):
|
| 58 |
+
subprocess.run(command, shell=True, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 59 |
|
| 60 |
+
def main():
|
| 61 |
+
ngrok_start(ngrokTokenFile,8081,'use ngrok',ngrok_use)
|
| 62 |
+
if not args.skip_prepare_environment:
|
| 63 |
+
launch_utils.prepare_environment()
|
| 64 |
+
run_command(f"""sed -i -e ''"s/dict()))/dict())).cuda()/g"'' /bushu/ui/repositories/stable-diffusion-stability-ai/ldm/util.py""")
|
| 65 |
+
run_command(f"""sed -i -e ''"s/stable/dict()))/dict())).cuda()/g"'' /bushu/ui/repositories/diffusion-stability-stable/ldm/util.py""")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
|
| 67 |
+
if args.test_server:
|
| 68 |
+
launch_utils.configure_for_tests()
|
|
|
|
| 69 |
|
| 70 |
+
launch_utils.start()
|
| 71 |
|
| 72 |
+
if __name__ == "__main__":
|
| 73 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|