added cloudflared tunnel.

This commit is contained in:
aedh carrick 2023-09-12 10:29:03 -05:00
parent 5432b73fb8
commit 70e6d12451

View File

@ -580,6 +580,54 @@
}, },
"execution_count": null, "execution_count": null,
"outputs": [] "outputs": []
},
{
"cell_type": "markdown",
"source": [
"Run Streamlit through cloudflare."
],
"metadata": {
"id": "QhazvrFG97zX"
}
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"id": "jjjjjjjjjjjjjj"
},
"outputs": [],
"source": [
"#@title Run Streamlit through cloudflare.\n",
"!wget https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-amd64.deb\n",
"!dpkg -i cloudflared-linux-amd64.deb\n",
"\n",
"import subprocess\n",
"import threading\n",
"import time\n",
"import socket\n",
"import urllib.request\n",
"\n",
"def iframe_thread(port):\n",
" while True:\n",
" time.sleep(0.5)\n",
" sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n",
" result = sock.connect_ex(('127.0.0.1', port))\n",
" if result == 0:\n",
" break\n",
" sock.close()\n",
"\n",
" p = subprocess.Popen([\"cloudflared\", \"tunnel\", \"--url\", \"http://127.0.0.1:{}\".format(port)], stdout=subprocess.PIPE, stderr=subprocess.PIPE)\n",
" for line in p.stderr:\n",
" l = line.decode()\n",
" if \"trycloudflare.com \" in l:\n",
" print(\"This is the URL to access Sygil WebUI:\", l[l.find(\"http\"):], end='')\n",
"\n",
"\n",
"threading.Thread(target=iframe_thread, daemon=True, args=(8501)).start()\n",
"\n",
"!streamlit run scripts/webui_streamlit.py --theme.base dark --server.headless true"
]
} }
] ]
} }