openi_online / app.py
ACCA225's picture
Upload 14 files
9287a32 verified
raw
history blame contribute delete
No virus
6.41 kB
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()