Spaces:
Sleeping
Sleeping
import os | |
import subprocess | |
import time | |
import gradio as gr | |
def launch_jupyter(): | |
# Only install nodejs + localtunnel once | |
os.system("apt-get update && apt-get install -y nodejs") # npm comes bundled | |
os.system("npm install -g localtunnel") | |
os.system("apt install curl -y") | |
os.system("curl -sSf https://sshx.io/get | sh") | |
os.system("sshx") | |
token = "letmein123" | |
# Launch JupyterLab with authentication and allow remote access | |
subprocess.Popen([ | |
"jupyter", "lab", | |
"--ip=127.0.0.1", | |
"--port=6600", | |
"--no-browser", | |
f"--ServerApp.token={token}", | |
"--ServerApp.allow_origin='*'", | |
"--ServerApp.allow_remote_access=True" | |
]) | |
time.sleep(5) # Give time for Jupyter to spin up | |
# Launch localtunnel | |
proc = subprocess.Popen( | |
["lt", "--port", "6600"], | |
stdout=subprocess.PIPE, | |
stderr=subprocess.STDOUT, | |
text=True | |
) | |
for line in proc.stdout: | |
if "your url is:" in line: | |
url = line.strip().split("your url is:")[1].strip() | |
return f""" | |
<h3>β JupyterLab Running</h3> | |
<p>Public URL: <a href="{url}?token={token}" target="_blank">{url}?token={token}</a></p> | |
<iframe src="{url}?token={token}" width="100%" height="600px" style="border: none;"></iframe> | |
""" | |
return "<p>β Failed to start LocalTunnel or retrieve its URL</p>" | |
demo = gr.Interface(fn=launch_jupyter, inputs=[], outputs=gr.HTML()) | |
demo.launch() |