File size: 4,219 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
from fastapi import FastAPI
import httpx
import os
import subprocess
import time
import threading
import os
#把ngrok填在这里
ngrok_token = "2czr8DkKCjtMcTVeSDguOI6eQ0u_5WQupdEu6RnNTKjwQ2BXU" #'2YypH9d2VXVL78HxF7g0lintH17_2GbtkFNFFngUkTZcyQ4SD'
edge = "edghts_2czrEA4yNUVzmxlhChyNFtY52TE"

url = os.getenv('OPENI_GRADIO_URL')
os.chdir('/sd')
def nginx():
    os.system("cp /tmp/code/sd2/proxy_nginx.conf ./")

    

    # 打印 url 的值
    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()
#os.system("wget https://openi.pcl.ac.cn/2575044704/sd-v1.7.0/raw/commit/f3cd7e9bacce0ce6d849e6377c64710b56a13016/webui.py -O webui.py")
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.")

# 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')

def ngrok(edge, ngrok_token):
    while True:
        #!ngrok tunnel --label edge={edge} --authtoken={ngrok_token} --region=ap http://localhost:7860
        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函数,另一个运行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()