File size: 6,407 Bytes
9287a32 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 |
from fastapi import FastAPI
import httpx
import os
import threading
#使用的库
os.system("pip install nvidia-ml-py3 wandb")
#print("替换webui.py")
#webpy()
import os
def create_symlinks(folder_paths, target_dir):
print('链接模型中')
# Create target directory if it doesn't exist
if not os.path.exists(target_dir):
os.makedirs(target_dir)
# Remove broken symlinks in target directory
for filename in os.listdir(target_dir):
target_path = os.path.join(target_dir, filename)
if os.path.islink(target_path) and not os.path.exists(target_path):
os.unlink(target_path)
# Create new symlinks
for source_path in folder_paths:
if not os.path.exists(source_path):
continue
if os.path.isdir(source_path):
for filename in os.listdir(source_path):
source_file_path = os.path.join(source_path, filename)
target_file_path = os.path.join(target_dir, filename)
if not os.path.exists(target_file_path):
os.symlink(source_file_path, target_file_path)
print(f'Created symlink for {filename} in {target_dir}')
else:
print(f'Symlink for {filename} already exists in {target_dir}')
else:
filename = os.path.basename(source_path)
target_file_path = os.path.join(target_dir, filename)
if not os.path.exists(target_file_path):
os.symlink(source_path, target_file_path)
print(f'Created symlink for {filename} in {target_dir}')
else:
print(f'Symlink for {filename} already exists in {target_dir}')
print('链接成功')
# Example usage:
source_folders = ['/pretrainmodel']
target_directory = '/sd/models/Stable-diffusion'
create_symlinks(source_folders, target_directory)
from pathlib import Path
import subprocess
import pandas as pd
import shutil
import os
import time
import re
import gc
import requests
import zipfile
import threading
import time
import socket
from concurrent.futures import ProcessPoolExecutor
import wandb
import base64
import os
import time
import wandb
import nvidia_smi
import os
import time
import wandb
#把ngrok填在这里
ngrok_token = "2bgnVJhlLqxUZhS1WyeaAtQA12F_6nQXrapUved4QSxYFn1cD"#'2YypH9d2VXVL78HxF7g0lintH17_2GbtkFNFFngUkTZcyQ4SD'
edge = "edghts_2cUdHbbxvMVOXsl0krDIc1SBv58"
import os
import subprocess
import time
import os
print("你的数据集文件:")
os.system("ls /tmp/dataset")
process = subprocess.Popen(["cp", "-r", "/tmp/dataset", "/sd/models/Stable-diffusion"])
# 获取 OPENI_GRADIO_URL 环境变量的值
url = os.getenv('OPENI_GRADIO_URL')
# 打印 url 的值
print("你的URL是:", url)
os.system(f"/usr/local/bin/python /usr/local/bin/jupyter-lab --ServerApp.shutdown_no_activity_timeout=1800 --TerminalManager.cull_inactive_timeout=1800 --TerminalManager.cull_interval=300 --MappingKernelManager.cull_idle_timeout=1800 --MappingKernelManager.cull_interval=300 --MappingKernelManager.cull_connected=True --MappingKernelManager.cull_busy=True --no-browser --ip=0.0.0.0 --allow-root --notebook-dir=/ --port=7860 --LabApp.token= --LabApp.allow_origin=* --LabApp.base_url={url}")
#os.system(f"ngrok tunnel --label edge={edge} --authtoken={ngrok_token} --region=ap http://localhost:7860 & /usr/local/bin/python /usr/local/bin/jupyter-lab --ServerApp.shutdown_no_activity_timeout=1800 --TerminalManager.cull_inactive_timeout=1800 --TerminalManager.cull_interval=300 --MappingKernelManager.cull_idle_timeout=1800 --MappingKernelManager.cull_interval=300 --MappingKernelManager.cull_connected=True --MappingKernelManager.cull_busy=True --no-browser --ip=0.0.0.0 --allow-root --notebook-dir=/ --port=7860 --LabApp.token= --LabApp.allow_origin=* --LabApp.base_url= & python/tmp /code/sd2/1.py")
# 定时关机,防止扣积分,如果不需要自动关机可以删掉
script_content = """#!/bin/bash
echo delay1
# 定义延时时间(28分钟)
delay=1830
# 等待一段时间
sleep $delay
echo KILLING PROCESS
# 执行命令
# 获取除了PID为8以外的所有进程的PID,并关闭它们
ps aux | awk '$2 != 80 {print $2}' | grep -v 'PID' | xargs kill -9
"""
script_content2 = """#!/bin/bash
# 定义延时时间(28分钟)
delay=1790
# 等待一段时间
sleep $delay
echo start_selenium
start_time=$(date +%s)
# 执行命令
#wget --wait 2 --random-wait --continue "https://openi.pcl.ac.cn/FASOXO/py_test/raw/branch/master/selenium.py" -O significant_script.py
python significant_script.py
end_time=$(date +%s)
elapsed_time=$((end_time - start_time))
echo "脚本执行时间:$elapsed_time 秒"
"""
script_path = "monitor_script.sh"
script_path2 = "monitor_script2.sh"
with open(script_path, "w") as script_file:
script_file.write(script_content)
try:
process = subprocess.Popen(["bash", script_path])
except KeyboardInterrupt:
print("Script execution interrupted.")
with open(script_path2, "w") as script_file:
script_file.write(script_content2)
try:
process = subprocess.Popen(["bash", script_path2])
except KeyboardInterrupt:
print("Script execution interrupted.")
# ngrok http 7860 --authtoken=2KPyfzQrHit97J02tARy1ckHJYd_69rJbgjpjnVVeuXD3j9tv --region=ap
#!python launch.py --ad-no-huggingface --no-download-sd-model --opt-channelslast --xformers --api --no-hashing --skip-torch-cuda-test & ngrok http 7860 --authtoken={你的ngrok_token} --region=ap
print('starting')
import threading
import os
def ngrok(edge, ngrok_token):
while True:
#os.system(f"ngrok tunnel --label edge={edge} --authtoken={ngrok_token} --region=ap http://localhost:7860")
pass
def webui():
os.system(f"python launch.py --port=8888 --subpath={url} --api-log --ckpt=/sd/models/Stable-diffusion/131-half.1.safetensors --api-auth=123:456 --ad-no-huggingface --no-download-sd-model --opt-channelslast --xformers --api --no-hashing --skip-torch-cuda-test")
def main():
global ngrok_token
global edge
# 创建两个线程,一个运行ngrok函数,另一个运行webui函数
ngrok_thread = threading.Thread(target=ngrok, args=(edge, ngrok_token))
webui_thread = threading.Thread(target=webui)
# 启动线程
ngrok_thread.start()
webui_thread.start()
# 等待两个线程完成
ngrok_thread.join()
webui_thread.join()
main()
|