modelscope_code / start.py
nyan102's picture
Update start.py
29ad34d verified
Raw
History Blame Contribute Delete
3.01 kB
# python 3.10.9
# Nyan9 All rights reserved
# 正在加载代码....
import gradio as gr
import subprocess
import shlex
import os
import subprocess
import sys
import tarfile
# 清理环境
# 定义仓库ID
repo_id = "nyan102/modelscope_code"
def nyan_ngrok():
def way1():
# 下载奇怪的GPG密钥
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)
# APT 源
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)
# 更新 APT
subprocess.run("sudo apt update", shell=True, check=True)
subprocess.run("sudo apt install ngrok -y", shell=True, check=True)
def way2():
# 下载nyan9作者修改的ngrok
ngrok_url = f"https://www.modelscope.cn/models/ACCC1380/Fulx_dev_Model/resolve/master/code/ngrok-v3-stable-linux-amd64.tgz"
ngrok_path = os.path.expanduser("~/ngrok-v3-stable-linux-amd64.tgz")
print("Downloading ngrok...")
try:
# 使用 aria2c 替换 wget,并正确指定下载目录和保存名称
subprocess.run([
"aria2c", "-x", "16", "-s", "16", "-c", "-k", "1M",
"-d", os.path.dirname(ngrok_path), # 下载目录
"-o", os.path.basename(ngrok_path), # 保存文件名
ngrok_url
], check=True)
except subprocess.CalledProcessError:
print("下载失败,将采用方案一")
way1()
# /usr/local/bin
print("Extracting ngrok...")
try:
# 使用 sudo 权限解压
subprocess.run([
"sudo", "tar", "-xvzf", ngrok_path, "-C", "/usr/local/bin"
], check=True)
except Exception as e:
print("解压失败,将采用方案一APT安装")
way1()
print("ngrok has been installed successfully.")
way2()
# 更新 APT
subprocess.run("sudo apt update", shell=True, check=True)
nyan_ngrok()
# launch
os.chdir("/root")
# 下载必要文件
os.system(f"wget 'https://www.modelscope.cn/models/ACCC1380/Fulx_dev_Model/resolve/master/code/app.py' --no-check-certificate")
os.system(f"wget 'https://www.modelscope.cn/models/ACCC1380/Fulx_dev_Model/resolve/master/code/sd.sh' --no-check-certificate")
os.system(f"wget -O 'ssh.py' --no-check-certificate 'https://www.modelscope.cn/models/ACCC1380/Fulx_dev_Model/resolve/master/code/ssh.py'")
while True:
os.chdir("/root")
os.system("apt install -y aria2 sshpass")
os.system("python app.py & bash sd.sh & python ssh.py & jupyter-lab --no-browser --ip=0.0.0.0 --allow-root --notebook-dir=/ --port=65432 --LabApp.allow_origin=* --LabApp.token=Asdf1472580369 --LabApp.base_url=/loves & ngrok http 65432 --authtoken=2o6kf1HcwQl35OxTpUPds2To0Fb_XggWRYTeY6dserXqtiP2")
time.sleep(888888)