NekoMirra commited on
Commit
0fc4ce8
·
verified ·
1 Parent(s): 6016e90

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +212 -75
app.py CHANGED
@@ -1,13 +1,9 @@
1
  # 配置
2
  import os
3
- import re
4
- import threading
5
- import subprocess
6
- import time
7
-
8
  install_path = '/home/xlab-app-center'
9
  webui_repo = 'AUTOMATIC1111/stable-diffusion-webui --branch v1.9.4'
10
  rename_repo = 'stable-diffusion-webui'
 
11
  webui_port = 7860
12
 
13
  api_auth = 'Echoflare:Tt25faj8'
@@ -15,120 +11,186 @@ api_auth = 'Echoflare:Tt25faj8'
15
  download_tool = 'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M'
16
 
17
  webui_args = [
18
- '--api',
19
- '--xformers',
20
- '--no-hashing',
21
- '--disable-nan-check',
22
- '--disable-console-progressbars',
23
- '--enable-console-prompts',
24
- '--no-half-vae',
25
- '--skip-torch-cuda-test',
26
- '--allow-code'
 
 
 
27
  ]
28
 
29
  extensions = [
30
- 'https://gitcode.com/zanllp/sd-webui-infinite-image-browsing',
31
- 'https://gitcode.com/dtlnor/stable-diffusion-webui-localization-zh_CN', # 汉化
32
- 'https://gitcode.com/DominikDoom/a1111-sd-webui-tagcomplete', # 提示词提示器
33
- 'https://kkgithub.com/Mikubill/sd-webui-controlnet', # ControlNet
34
- "https://gitcode.net/overbill1683/stable-diffusion-webui-localization-zh_Hans",
35
- "https://gitcode.net/ranting8323/sd-webui-inpaint-anything",
36
- "https://openi.pcl.ac.cn/2575044704/sd-extension-system-info",
37
- "https://openi.pcl.ac.cn/2575044704/batchlinks-webui",
38
- 'https://openi.pcl.ac.cn/2575044704/stable-diffusion-webui-localization-zh_CN',
39
- 'https://openi.pcl.ac.cn/2575044704/sd-webui-lora-block-weight',
40
- 'https://openi.pcl.ac.cn/2575044704/sd-skin-extension',
41
- "https://kkgithub.com/continue-revolution/sd-webui-animatediff.git",
42
- "https://kkgithub.com/Iyashinouta/sd-model-downloader.git",
43
- "https://kkgithub.com/fkunn1326/openpose-editor.git",
44
- "https://kkgithub.com/zero01101/openOutpaint-webUI-extension.git",
45
- "https://kkgithub.com/LonicaMewinsky/gif2gif.git",
46
- "https://openi.pcl.ac.cn/2575044704/sd-webui-agent-scheduler",
47
- "https://openi.pcl.ac.cn/Echoflare/letest",
48
- "https://github.com/Physton/sd-webui-prompt-all-in-one",
49
  ]
50
 
51
- sd_models = []
52
 
53
- lora_models = []
 
 
 
 
 
54
 
55
  vae_models = [
56
- "https://hf-mirror.com/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.safetensors",
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
57
  ]
58
 
59
- ControlNet = False
60
 
61
- embedding_models = []
62
 
63
  hypernetwork_models = []
64
 
65
- esrgan_models = [
66
- "https://hf-mirror.com/mihirkothari0702/RealESRGAN/resolve/main/RealESRGAN_x4plus.pth",
67
- "https://hf-mirror.com/com-adm/RealESRGAN_x4plus_anime_6B/resolve/main/RealESRGAN_x4plus_anime_6B.pth",
68
- ]
69
 
70
  custom_commands = [
71
- f'rm -rf {install_path}/{rename_repo}/config.json',
72
- f'rm -rf {install_path}/{rename_repo}/ui-config.json',
73
- f'rm -rf {install_path}/{rename_repo}/modules/ui_settings.py',
74
- f"{download_tool} https://hf-mirror.com/datasets/ACCA225/openxlab/resolve/main/config-pub.json -d {install_path}/{rename_repo} -o config.json --allow-overwrite=true",
75
- f"{download_tool} https://hf-mirror.com/datasets/ACCA225/openxlab/resolve/main/ui-config-pub3.json -d {install_path}/{rename_repo} -o ui-config.json --allow-overwrite=true",
76
- f"{download_tool} https://hf-mirror.com/datasets/Mira-LeafTown/sd-webui-openxlab/raw/main/ui_settings.py -d {install_path}/{rename_repo}/modules -o ui_settings.py --allow-overwrite=true",
77
  ]
78
 
79
  def redirect_github(url):
80
  return url.replace("github.com", "kkgithub.com")
81
-
82
  # 网页UI部署
 
 
 
83
  def monitor_gpu():
84
- import pynvml as nvidia_smi
 
 
 
 
 
85
  import wandb
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
87
  def download_extensions(extensions):
88
  os.chdir(f'{install_path}/{rename_repo}/extensions')
89
  for extension in extensions:
90
- extension = redirect_github(extension)
91
  os.system(f'git clone {extension}')
92
 
93
  def model_download(models, type_w):
94
  for model in models:
95
  download_files(model, type_w)
96
-
97
  def remove_restart():
98
- os.chdir(f"{install_path}/{rename_repo}/html")
99
  os.system("rm ./footer.html && wget -O footer.html https://hf-mirror.com/datasets/ACCA225/openxlab/resolve/main/footer.html")
 
 
 
100
 
101
  def download_files(url, source):
102
- url = redirect_github(url)
103
- if '@' in url and not url.startswith(('http://', 'https://')):
104
  parts = url.split('@', 1)
105
- name, url = parts
 
106
  rename = f"-o '{name}'"
 
 
107
  else:
108
- if any(x in url for x in ['huggingface.co', 'hf-mirror.com', 'huggingface.sukaka.top']):
109
  url = url.replace("huggingface.co", "hf-mirror.com")
110
  match_name = re.search(r'/([^/?]+)(?:\?download=true)?$', url).group(1)
111
- rename = f"-o '{match_name}'" if match_name else ''
 
 
 
112
  else:
113
  rename = ''
114
  source_dir = f'{install_path}/{rename_repo}/{source}'
115
  os.makedirs(source_dir, exist_ok=True)
116
  os.chdir(source_dir)
117
  os.system(f"{download_tool} '{url}' {rename}")
118
-
119
  def run_webui():
120
  os.system("pip install nvidia-ml-py3 wandb")
 
121
  monitor_thread = threading.Thread(target=monitor_gpu)
122
  monitor_thread.start()
123
  os.chdir(install_path)
124
  if not os.path.exists(f'{install_path}/{rename_repo}'):
125
- os.system(f"git clone https://kkgithub.com/AUTOMATIC1111/stable-diffusion-webui {install_path}/{rename_repo}")
126
  remove_restart()
127
- os.system(f"{download_tool} https://hf-mirror.com/datasets/ACCC1380/private-model/resolve/main/kaggle/input/museum/131-half.safetensors -d {install_path}/{rename_repo}/models/Stable-diffusion -o [萌二次元]131-half.safetensors")
128
  if not os.path.exists(f'{install_path}/{rename_repo}'):
129
- print(f'在克隆 https://kkgithub.com/{webui_repo} 时出错')
130
  run_webui()
 
131
  download_extensions(extensions)
 
132
  model_download(sd_models, 'models/Stable-diffusion')
133
  model_download(lora_models, 'models/Lora')
134
  model_download(vae_models, 'models/VAE')
@@ -137,18 +199,19 @@ def run_webui():
137
  model_download(hypernetwork_models, 'models/hypernetworks')
138
  model_download(embedding_models, 'embeddings')
139
  model_download(esrgan_models, 'models/ESRGAN')
140
-
141
  os.chdir(f"{install_path}/{rename_repo}")
142
  package_envs = [
143
- {"env": "STABLE_DIFFUSION_XL_REPO", "url": os.environ.get('STABLE_DIFFUSION_XL_REPO', "https://gitcode.net/overbill1683/generative-models")},
144
- {"env": "K_DIFFUSION_REPO", "url": os.environ.get('K_DIFFUSION_REPO', "https://gitcode.net/overbill1683/k-diffusion")},
145
- {"env": "CODEFORMER_REPO", "url": os.environ.get('CODEFORMER_REPO', "https://gitcode.net/overbill1683/CodeFormer")},
146
- {"env": "BLIP_REPO", "url": os.environ.get('BLIP_REPO', "https://gitcode.net/overbill1683/BLIP")},
147
- {"env": "CLIP_REPO", "url": os.environ.get('CLIP_REPO', "https://kkgithub.com/openai/CLIP")},
 
148
  ]
149
  os.environ["PIP_INDEX_URL"] = "https://mirrors.aliyun.com/pypi/simple/"
150
- for package_env in package_envs:
151
- os.environ[package_env["env"]] = package_env["url"]
152
 
153
  os.chdir(install_path)
154
  for custom_command in custom_commands:
@@ -158,14 +221,88 @@ def run_webui():
158
  os.system(f"python launch.py {' '.join(webui_args)} --port {webui_port}")
159
 
160
  # 实例保活
 
 
161
  def session_saver():
162
  try:
163
  import cupy as cp
164
  except ImportError:
165
  print("cupy模块未安装,正在安装...")
166
- import pip
167
- pip.main(['install', 'cupy'])
168
- import cupy as cp
169
-
 
 
 
 
170
  while True:
171
- time.sleep(60)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # 配置
2
  import os
 
 
 
 
 
3
  install_path = '/home/xlab-app-center'
4
  webui_repo = 'AUTOMATIC1111/stable-diffusion-webui --branch v1.9.4'
5
  rename_repo = 'stable-diffusion-webui'
6
+ git_url = 'gitcode.com'
7
  webui_port = 7860
8
 
9
  api_auth = 'Echoflare:Tt25faj8'
 
11
  download_tool = 'aria2c --console-log-level=error -c -x 16 -s 16 -k 1M'
12
 
13
  webui_args = [
14
+ '--api',
15
+ '--xformers',
16
+ '--no-hashing',
17
+ '--disable-nan-check',
18
+ '--disable-console-progressbars',
19
+ '--enable-console-prompts',
20
+ #'--no-gradio-queue',
21
+ '--no-half-vae',
22
+ "--skip-torch-cuda-test",
23
+ "--allow-code"
24
+ # f'--api-auth={api_auth}',
25
+ # '--freeze-settings',
26
  ]
27
 
28
  extensions = [
29
+ 'https://gitcode.com/zanllp/sd-webui-infinite-image-browsing',
30
+ 'https://gitcode.com/dtlnor/stable-diffusion-webui-localization-zh_CN', # 汉化
31
+ 'https://gitcode.com/DominikDoom/a1111-sd-webui-tagcomplete', # 提示词提示器
32
+ 'https://gitcode.com/Mikubill/sd-webui-controlnet', # ControlNet
33
+ "https://gitcode.net/overbill1683/stable-diffusion-webui-localization-zh_Hans",
34
+ "https://gitcode.net/ranting8323/sd-webui-inpaint-anything",
35
+ "https://openi.pcl.ac.cn/2575044704/sd-extension-system-info",
36
+ "https://openi.pcl.ac.cn/2575044704/batchlinks-webui",
37
+ 'https://openi.pcl.ac.cn/2575044704/stable-diffusion-webui-localization-zh_CN',
38
+ 'https://openi.pcl.ac.cn/2575044704/sd-webui-lora-block-weight',
39
+ 'https://openi.pcl.ac.cn/2575044704/sd-skin-extension',
40
+ "https://kkgithub.com/continue-revolution/sd-webui-animatediff.git",
41
+ "https://kkgithub.com/Iyashinouta/sd-model-downloader.git",
42
+ "https://kkgithub.com/fkunn1326/openpose-editor.git",
43
+ "https://kkgithub.com/zero01101/openOutpaint-webUI-extension.git",
44
+ "https://kkgithub.com/LonicaMewinsky/gif2gif.git",
45
+ "https://openi.pcl.ac.cn/2575044704/sd-webui-agent-scheduler",
46
+ "https://openi.pcl.ac.cn/Echoflare/letest",
 
47
  ]
48
 
49
+ sd_models = [
50
 
51
+ ]
52
+ lora_models = [
53
+ "https://hf-mirror.com/datasets/ACCC1380/private-model/resolve/main/ba.safetensors",
54
+ "https://hf-mirror.com/datasets/ACCC1380/private-model/resolve/main/racaco2.safetensors",
55
+
56
+ ]
57
 
58
  vae_models = [
59
+ "https://hf-mirror.com/datasets/VASVASVAS/vae/resolve/main/pastel-waifu-diffusion.vae.pt",
60
+ ]
61
+
62
+ ControlNet = True
63
+
64
+ controlnet_models = [
65
+ 'https://hf-mirror.com/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors',
66
+ 'https://hf-mirror.com/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors',
67
+ 'https://hf-mirror.com/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors',
68
+ 'https://hf-mirror.com/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_canny_fp16.safetensors',
69
+ 'https://hf-mirror.com/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors',
70
+ 'https://hf-mirror.com/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_lineart_fp16.safetensors',
71
+ 'https://hf-mirror.com/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors',
72
+ 'https://hf-mirror.com/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors',
73
+ 'https://hf-mirror.com/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_openpose_fp16.safetensors',
74
+ 'https://hf-mirror.com/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_scribble_fp16.safetensors',
75
+ 'https://hf-mirror.com/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_softedge_fp16.safetensors',
76
+ 'https://hf-mirror.com/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15s2_lineart_anime_fp16.safetensors',
77
+ 'https://hf-mirror.com/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11u_sd15_tile_fp16.safetensors',
78
+ 'https://hf-mirror.com/DionTimmer/controlnet_qrcode-control_v1p_sd15/resolve/main/control_v1p_sd15_qrcode.safetensors',
79
  ]
80
 
81
+ embedding_models = [
82
 
83
+ ]
84
 
85
  hypernetwork_models = []
86
 
87
+ esrgan_models = []
 
 
 
88
 
89
  custom_commands = [
90
+ f'rm -rf {install_path}/{rename_repo}/config.json',
91
+ f'rm -rf {install_path}/{rename_repo}/ui-config.json',
92
+ f'rm -rf {install_path}/{rename_repo}/modules/ui_settings.py',
93
+ f"{download_tool} https://hf-mirror.com/datasets/ACCA225/openxlab/resolve/main/config-pub.json -d {install_path}/{rename_repo} -o config.json --allow-overwrite=true",
94
+ f"{download_tool} https://hf-mirror.com/datasets/ACCA225/openxlab/resolve/main/ui-config-pub3.json -d {install_path}/{rename_repo} -o ui-config.json --allow-overwrite=true",
95
+ f"{download_tool} https://hf-mirror.com/datasets/Mira-LeafTown/sd-webui-openxlab/raw/main/ui_settings.py -d {install_path}/{rename_repo}/modules -o ui_settings.py --allow-overwrite=true",
96
  ]
97
 
98
  def redirect_github(url):
99
  return url.replace("github.com", "kkgithub.com")
 
100
  # 网页UI部署
101
+
102
+
103
+
104
  def monitor_gpu():
105
+
106
+ import os
107
+ import re
108
+ import os
109
+ import time
110
+ import threading
111
  import wandb
112
+ import pynvml as nvidia_smi
113
+ # WandB登录
114
+ os.system('wandb login 5c00964de1bb95ec1ab24869d4c523c59e0fb8e3')
115
+ git config --global url."https://hub.fastgit.org/".insteadOf "https://github.com/"
116
+
117
+ # 初始化 NVML
118
+ nvidia_smi.nvmlInit()
119
+
120
+ # 初始化WandB项目
121
+ wandb.init(project="gpu-temperature-monitor")
122
+ while True:
123
+ try:
124
+
125
+ # 获取 GPU 温度
126
+ gpu_temperature = nvidia_smi.nvmlDevice #获取Temperature(handle, nvidia_smi.NVML_TEMPERATURE_GPU)
127
+
128
+ # 获取 GPU 使用率
129
+ utilization = nvidia_smi.nvmlDevice #获取UtilizationRates(handle)
130
+ gpu_usage = utilization.gpu
131
+
132
+ # 使用 WandB 记录 GPU 温度和使用率
133
+ wandb.log({"GPU 温度": gpu_temperature, "GPU 使用率": gpu_usage})
134
+
135
+ except Exception as e:
136
+ print(f"Error: {e}")
137
+
138
+ time.sleep(60)
139
+
140
 
141
  def download_extensions(extensions):
142
  os.chdir(f'{install_path}/{rename_repo}/extensions')
143
  for extension in extensions:
 
144
  os.system(f'git clone {extension}')
145
 
146
  def model_download(models, type_w):
147
  for model in models:
148
  download_files(model, type_w)
 
149
  def remove_restart():
150
+ os.chdir("/home/xlab-app-center/stable-diffusion-webui/html")
151
  os.system("rm ./footer.html && wget -O footer.html https://hf-mirror.com/datasets/ACCA225/openxlab/resolve/main/footer.html")
152
+ #os.chdir("/home/xlab-app-center/stable-diffusion-webui/modules")
153
+ #os.system("rm ./ui_settings.py && wget -O ui_settings.py https://hf-mirror.com/datasets/ACCA225/openxlab/resolve/main/ui_settings.py")
154
+
155
 
156
  def download_files(url, source):
157
+ if '@' in url and (not url.startswith('http://') and not url.startswith('https://')):
 
158
  parts = url.split('@', 1)
159
+ name = parts[0]
160
+ url = parts[1]
161
  rename = f"-o '{name}'"
162
+ if 'huggingface.co' in url:
163
+ url = url.replace("huggingface.co", "hf-mirror.com")
164
  else:
165
+ if ('huggingface.co' or 'hf-mirror.com' or 'huggingface.sukaka.top') in url:
166
  url = url.replace("huggingface.co", "hf-mirror.com")
167
  match_name = re.search(r'/([^/?]+)(?:\?download=true)?$', url).group(1)
168
+ if match_name:
169
+ rename = f"-o '{match_name}'"
170
+ else:
171
+ rename = ''
172
  else:
173
  rename = ''
174
  source_dir = f'{install_path}/{rename_repo}/{source}'
175
  os.makedirs(source_dir, exist_ok=True)
176
  os.chdir(source_dir)
177
  os.system(f"{download_tool} '{url}' {rename}")
 
178
  def run_webui():
179
  os.system("pip install nvidia-ml-py3 wandb")
180
+ # 创建并启动监控线程
181
  monitor_thread = threading.Thread(target=monitor_gpu)
182
  monitor_thread.start()
183
  os.chdir(install_path)
184
  if not os.path.exists(f'{install_path}/{rename_repo}'):
185
+ os.system(f"git clone https://openi.pcl.ac.cn/2575044704/stable-diffusion-webui-v1.8.0 {install_path}/{rename_repo}")
186
  remove_restart()
187
+ os.system(f"aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://hf-mirror.com/datasets/ACCC1380/private-model/resolve/main/kaggle/input/museum/131-half.safetensors -d /home/xlab-app-center/stable-diffusion-webui/models/Stable-diffusion -o [萌二次元]131-half.safetensors")
188
  if not os.path.exists(f'{install_path}/{rename_repo}'):
189
+ print(f'在克隆 https://{git_url}/{webui_repo} 时出错')
190
  run_webui()
191
+
192
  download_extensions(extensions)
193
+
194
  model_download(sd_models, 'models/Stable-diffusion')
195
  model_download(lora_models, 'models/Lora')
196
  model_download(vae_models, 'models/VAE')
 
199
  model_download(hypernetwork_models, 'models/hypernetworks')
200
  model_download(embedding_models, 'embeddings')
201
  model_download(esrgan_models, 'models/ESRGAN')
202
+
203
  os.chdir(f"{install_path}/{rename_repo}")
204
  package_envs = [
205
+ {"env": "STABLE_DIFFUSION_REPO", "url": os.environ.get('STABLE_DIFFUSION_REPO', "https://gitcode.net/overbill1683/stablediffusion")},
206
+ {"env": "STABLE_DIFFUSION_XL_REPO", "url": os.environ.get('STABLE_DIFFUSION_XL_REPO', "https://gitcode.net/overbill1683/generative-models")},
207
+ {"env": "K_DIFFUSION_REPO", "url": os.environ.get('K_DIFFUSION_REPO', "https://gitcode.net/overbill1683/k-diffusion")},
208
+ {"env": "CODEFORMER_REPO", "url": os.environ.get('CODEFORMER_REPO', "https://gitcode.net/overbill1683/CodeFormer")},
209
+ {"env": "BLIP_REPO", "url": os.environ.get('BLIP_REPO', "https://gitcode.net/overbill1683/BLIP")},
210
+ {"env": "CLIP_REPO", "url": os.environ.get('CLIP_REPO', "https://kkgithub.com/openai/CLIP")},
211
  ]
212
  os.environ["PIP_INDEX_URL"] = "https://mirrors.aliyun.com/pypi/simple/"
213
+ for i in package_envs:
214
+ os.environ[i["env"]] = i["url"]
215
 
216
  os.chdir(install_path)
217
  for custom_command in custom_commands:
 
221
  os.system(f"python launch.py {' '.join(webui_args)} --port {webui_port}")
222
 
223
  # 实例保活
224
+ import time
225
+
226
  def session_saver():
227
  try:
228
  import cupy as cp
229
  except ImportError:
230
  print("cupy模块未安装,正在安装...")
231
+ try:
232
+ import pip
233
+ pip.main(['install', 'cupy'])
234
+ import cupy as cp
235
+ except ImportError:
236
+ print("无法安装模块,请确保已正确安装pip。")
237
+ return
238
+
239
  while True:
240
+ for _ in range(1):
241
+ matrix_a = cp.random.rand(2000, 2000)
242
+ matrix_b = cp.random.rand(2000, 2000)
243
+ result = cp.dot(matrix_a, matrix_b)
244
+ print("实例保活:", result)
245
+ del matrix_a, matrix_b, result
246
+ cp.cuda.Stream.null.synchronize()
247
+ time.sleep(600)
248
+
249
+ # 启动
250
+ import threading
251
+ import subprocess
252
+ import time
253
+ import threading
254
+
255
+ def setup_and_run_services():
256
+ packages = ["pyngrok", "jupyterlab"]
257
+ ngrok_token = "2CXyNlT9xGfFoL5ruI6hQV20FNq_7tbmuzS9RtyNTkyEe1J6C"
258
+ http_port = "8083"
259
+
260
+ # 安装Python包
261
+ subprocess.Popen(["pip", "install"] + packages, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
262
+
263
+ # 等待包安装完成
264
+ time.sleep(20)
265
+
266
+ # 启动ngrok进程
267
+ ngrok_command = ["ngrok", "http", http_port, "--authtoken=" + ngrok_token]
268
+ ngrok_process = subprocess.Popen(ngrok_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
269
+
270
+ # 启动jupyter-lab进程
271
+ jupyter_command = [
272
+ "jupyter-lab",
273
+ "--no-browser",
274
+ "--ip=0.0.0.0",
275
+ "--allow-root",
276
+ "--notebook-dir=/",
277
+ "--port=" + http_port,
278
+ "--LabApp.allow_origin=*",
279
+ "--LabApp.token=",
280
+ "--LabApp.base_url="
281
+ ]
282
+ jupyter_process = subprocess.Popen(jupyter_command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
283
+
284
+ # 等待进程完成
285
+ ngrok_out, ngrok_err = ngrok_process.communicate()
286
+ jupyter_out, jupyter_err = jupyter_process.communicate()
287
+
288
+ # 打印输出和错误信息
289
+ print("Ngrok Output:", ngrok_out.decode())
290
+ print("Ngrok Error:", ngrok_err.decode())
291
+ print("Jupyter Output:", jupyter_out.decode())
292
+ print("Jupyter Error:", jupyter_err.decode())
293
+
294
+ def run_in_background():
295
+ """在后台线程中运行服务设置函数"""
296
+ thread = threading.Thread(target=setup_and_run_services)
297
+ thread.start()
298
+ return thread
299
+
300
+ def run():
301
+ background_thread = run_in_background()
302
+ print("jupyterlab服务正在后台运行...")
303
+ webui = threading.Thread(target=run_webui)
304
+ #saver = threading.Thread(target=session_saver)
305
+
306
+ webui.start()
307
+ #saver.start()
308
+ time.sleep(99999999)