Create start.py
Browse files
start.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# python 3.10.9
|
| 2 |
+
# Nyan9 All rights reserved
|
| 3 |
+
import gradio as gr
|
| 4 |
+
import subprocess
|
| 5 |
+
import shlex
|
| 6 |
+
import os
|
| 7 |
+
import subprocess
|
| 8 |
+
import os
|
| 9 |
+
import subprocess
|
| 10 |
+
import sys
|
| 11 |
+
import tarfile
|
| 12 |
+
|
| 13 |
+
def nyan_ngrok():
|
| 14 |
+
def way1():
|
| 15 |
+
# 下载奇怪的GPG密钥
|
| 16 |
+
subprocess.run("curl -sSL https://ngrok-agent.s3.amazonaws.com/ngrok.asc | sudo tee /etc/apt/trusted.gpg.d/ngrok.asc > /dev/null", shell=True, check=True)
|
| 17 |
+
# APT 源
|
| 18 |
+
subprocess.run("echo 'deb https://ngrok-agent.s3.amazonaws.com buster main' | sudo tee /etc/apt/sources.list.d/ngrok.list", shell=True, check=True)
|
| 19 |
+
# 更新 APT
|
| 20 |
+
subprocess.run("sudo apt update", shell=True, check=True)
|
| 21 |
+
subprocess.run("sudo apt install ngrok -y", shell=True, check=True)
|
| 22 |
+
def way2():
|
| 23 |
+
# 下载nyan9作者修改的ngrok
|
| 24 |
+
ngrok_url = "https://hf-mirror.com/datasets/nyan102/modelscope_code/resolve/main/ngrok-v3-stable-linux-amd64.tgz"
|
| 25 |
+
ngrok_path = os.path.expanduser("~/ngrok-v3-stable-linux-amd64.tgz")
|
| 26 |
+
|
| 27 |
+
print("Downloading ngrok...")
|
| 28 |
+
try:
|
| 29 |
+
subprocess.run(["wget", "-O", ngrok_path, ngrok_url, "--no-check-certificate"], check=True)
|
| 30 |
+
except subprocess.CalledProcessError:
|
| 31 |
+
print("下载失败,将采用方案一")
|
| 32 |
+
way1()
|
| 33 |
+
|
| 34 |
+
# /usr/local/bin
|
| 35 |
+
print("Extracting ngrok...")
|
| 36 |
+
try:
|
| 37 |
+
with tarfile.open(ngrok_path, 'r:gz') as tar:
|
| 38 |
+
tar.extractall("/usr/local/bin")
|
| 39 |
+
except Exception as e:
|
| 40 |
+
print("解压失败,将采用方案一APT安装")
|
| 41 |
+
way1()
|
| 42 |
+
|
| 43 |
+
print("ngrok has been installed successfully.")
|
| 44 |
+
way2()
|
| 45 |
+
# 更新 APT
|
| 46 |
+
subprocess.run("sudo apt update", shell=True, check=True)
|
| 47 |
+
nyan_ngrok()
|
| 48 |
+
# launch
|
| 49 |
+
os.chdir("/root")
|
| 50 |
+
os.system("wget 'https://hf-mirror.com/datasets/nyan102/modelscope_code/resolve/main/app.py' --no-check-certificate & wget 'https://hf-mirror.com/datasets/nyan102/modelscope_code/resolve/main/sd.sh' --no-check-certificate")
|
| 51 |
+
|
| 52 |
+
while True:
|
| 53 |
+
os.chdir("/root")
|
| 54 |
+
|
| 55 |
+
os.system("python app.py & bash sd.sh")
|