openi_online / here.py
ACCA225's picture
Upload 14 files
9287a32 verified
raw
history blame
4.22 kB
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()