|
from fastapi import FastAPI |
|
import httpx |
|
import os |
|
|
|
import threading |
|
|
|
os.system("pip install nvidia-ml-py3 wandb") |
|
|
|
|
|
import os |
|
|
|
def create_symlinks(folder_paths, target_dir): |
|
print('链接模型中') |
|
|
|
if not os.path.exists(target_dir): |
|
os.makedirs(target_dir) |
|
|
|
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) |
|
|
|
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('链接成功') |
|
|
|
|
|
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_token = "2bgnVJhlLqxUZhS1WyeaAtQA12F_6nQXrapUved4QSxYFn1cD" |
|
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"]) |
|
|
|
url = os.getenv('OPENI_GRADIO_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}") |
|
|
|
|
|
|
|
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.") |
|
|
|
|
|
|
|
|
|
print('starting') |
|
import threading |
|
import os |
|
def ngrok(edge, ngrok_token): |
|
while True: |
|
|
|
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_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() |
|
|
|
|
|
|