File size: 1,965 Bytes
265a0b2 eee90f8 265a0b2 e023a0c 22d761a 5c5b6c3 eee90f8 5c5b6c3 22d761a 5c5b6c3 eee90f8 5c5b6c3 eee90f8 22d761a eee90f8 265a0b2 eee90f8 265a0b2 22d761a 6ce6262 265a0b2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | {
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import threading\n",
"import subprocess\n",
"import time\n",
"import os\n",
"#/content/esay\n",
"%cd /content/esay/sd-ui-files\n",
"use_remote = True # @param {type:\"boolean\"}\n",
"use_cloudflare = True # @param {type:\"boolean\"}\n",
"\n",
"def start_tunnle():\n",
" open(\"/content/output.log\", \"w\").close()\n",
" # 循环检测文件内容,直到存在\"http://127.0.0.1:9090\"。\n",
" while not \"http://localhost:9000/\" in open(\"/content/output.log\", \"r\").read():\n",
" time.sleep(1)\n",
" clear_output() \n",
" if ngrok_token:\n",
" try:\n",
" from pyngrok import ngrok\n",
" ngrok_tunnel = ngrok.connect(9000, \"http\")\n",
" print(\"ngrok_tunnel:\", ngrok_tunnel)\n",
" except Exception as e:\n",
" print(\"ngrok 连接失败:\", e)\n",
"\n",
" if use_cloudflare:\n",
" try:\n",
" from pycloudflared import try_cloudflare\n",
" cloudflare_url = try_cloudflare(9000, verbose=False)\n",
" print(\"cloudflare_tunnel:\", cloudflare_url)\n",
" except Exception as e:\n",
" print(\"cloudflare 连接失败:\", e)\n",
"\n",
" if use_remote:\n",
" try:\n",
" !ssh -R 80:127.0.0.1:9000 -o StrictHostKeyChecking=no -i /content/id_rsa remote.moe 2>&1 | tee -a /content/tunnel.log\n",
" except Exception as e:\n",
" print(\"cloudflare 连接失败:\", e)\n",
"\n",
"threading.Thread(target=start_tunnle, daemon=True).start()\n",
"\n",
"!python ./scripts/check_modules.py --launch-uvicorn 2>&1 | tee /content/output.log\n",
"#!python ./ui/main.py"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
|