|
from fastapi import FastAPI |
|
import httpx |
|
import os |
|
import subprocess |
|
import time |
|
import threading |
|
import os |
|
|
|
ngrok_token = "2czr8DkKCjtMcTVeSDguOI6eQ0u_5WQupdEu6RnNTKjwQ2BXU" |
|
edge = "edghts_2czrEA4yNUVzmxlhChyNFtY52TE" |
|
|
|
url = os.getenv('OPENI_GRADIO_URL') |
|
os.chdir('/sd') |
|
def nginx(): |
|
os.system("cp /tmp/code/sd2/proxy_nginx.conf ./") |
|
|
|
|
|
|
|
|
|
os.system(f"sed -i 's|<your_url>|{url}|g' proxy_nginx.conf") |
|
os.system("sed -i 's|7860|8888|g' proxy_nginx.conf") |
|
nginx() |
|
|
|
print("你的数据集文件:") |
|
os.system("ls /tmp/dataset") |
|
process = subprocess.Popen(["cp", "-r", "/tmp/dataset", "/sd/models/Stable-diffusion"]) |
|
|
|
|
|
script_content = """#!/bin/bash |
|
|
|
|
|
echo 你正在使用bilibili_Nyan9的脚本,请勿外传本项目。有问题联系QQ2575044704 |
|
# 定义延时时间(28分钟) |
|
delay=1810 |
|
|
|
# 等待一段时间 |
|
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=1740 |
|
|
|
# 等待一段时间 |
|
sleep $delay |
|
echo start_selenium |
|
|
|
start_time=$(date +%s) |
|
|
|
# 执行命令 |
|
#wget --random-wait --tries=10 --continue "https://openi.pcl.ac.cn/FASOXO/py_test/raw/branch/master/selenium.py" -O significant_script.py |
|
#wget --random-wait --tries=10 --continue "https://openi.pcl.ac.cn/FASOXO/py_test/raw/branch/master/selenium.py" -O significant_script.py |
|
#wget --random-wait --tries=10 --continue "https://openi.pcl.ac.cn/FASOXO/py_test/raw/branch/master/selenium.py" -O significant_script.py |
|
#wget --random-wait --tries=10 --continue "https://openi.pcl.ac.cn/FASOXO/py_test/raw/branch/master/selenium.py" -O significant_script.py |
|
|
|
python /tmp/code/sd2/sel.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.") |
|
|
|
|
|
|
|
|
|
print('starting') |
|
|
|
def ngrok(edge, ngrok_token): |
|
while True: |
|
|
|
os.system(f"ngrok tunnel --label edge={edge} --authtoken={ngrok_token} --region=ap http://localhost:7860") |
|
|
|
def webui(): |
|
os.chdir('/sd') |
|
os.system("nginx -c /sd/proxy_nginx.conf && echo nginx执行成功") |
|
command = f'python launch.py --api-log --ckpt=/sd/models/Stable-diffusion/131-half.1.safetensors --ad-no-huggingface --no-download-sd-model --opt-channelslast --xformers --api --no-hashing --skip-torch-cuda-test --subpath={url}' |
|
os.system(f'{command}/sd1 & {command}/sd2 --port=7862 & {command}/sd3 --port=7863 & {command}/sd4 --port=7864 & python /tmp/code/sd2/the_flask2.py & python /tmp/code/sd2/the_flask_ngrok.py') |
|
|
|
def main(): |
|
global ngrok_token |
|
global edge |
|
|
|
|
|
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() |
|
|
|
|
|
|