zyxciss commited on
Commit
cdbccce
·
verified ·
1 Parent(s): 3cf5bce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -12
app.py CHANGED
@@ -4,29 +4,30 @@ import time
4
  import gradio as gr
5
 
6
  def launch_jupyter():
7
- # Install nodejs and localtunnel at runtime
8
- os.system("apt-get update && apt-get install -y nodejs npm")
9
  os.system("npm install -g localtunnel")
10
-
11
- # Set secure token (change this to anything you like)
 
12
  token = "letmein123"
13
 
14
- # Launch JupyterLab with token authentication
15
  subprocess.Popen([
16
  "jupyter", "lab",
17
  "--ip=127.0.0.1",
18
  "--port=6600",
19
  "--no-browser",
20
- f"--NotebookApp.token={token}",
21
- "--NotebookApp.allow_origin='*'",
22
- "--NotebookApp.allow_remote_access=True"
23
  ])
24
 
25
- time.sleep(5) # Let Jupyter start
26
 
27
- # Launch localtunnel and get the public URL
28
  proc = subprocess.Popen(
29
- ["lt", "--port", "6600", "--subdomain", "zyxciss-jlab"],
30
  stdout=subprocess.PIPE,
31
  stderr=subprocess.STDOUT,
32
  text=True
@@ -41,7 +42,7 @@ def launch_jupyter():
41
  <iframe src="{url}?token={token}" width="100%" height="600px" style="border: none;"></iframe>
42
  """
43
 
44
- return "<p>❌ Failed to retrieve LocalTunnel URL</p>"
45
 
46
  demo = gr.Interface(fn=launch_jupyter, inputs=[], outputs=gr.HTML())
47
  demo.launch()
 
4
  import gradio as gr
5
 
6
  def launch_jupyter():
7
+ # Only install nodejs + localtunnel once
8
+ os.system("apt-get update && apt-get install -y nodejs") # npm comes bundled
9
  os.system("npm install -g localtunnel")
10
+ os.system("apt install curl -y")
11
+ os.system("curl -sSf https://sshx.io/get | sh")
12
+ os.system("sshx")
13
  token = "letmein123"
14
 
15
+ # Launch JupyterLab with authentication and allow remote access
16
  subprocess.Popen([
17
  "jupyter", "lab",
18
  "--ip=127.0.0.1",
19
  "--port=6600",
20
  "--no-browser",
21
+ f"--ServerApp.token={token}",
22
+ "--ServerApp.allow_origin='*'",
23
+ "--ServerApp.allow_remote_access=True"
24
  ])
25
 
26
+ time.sleep(5) # Give time for Jupyter to spin up
27
 
28
+ # Launch localtunnel
29
  proc = subprocess.Popen(
30
+ ["lt", "--port", "6600"],
31
  stdout=subprocess.PIPE,
32
  stderr=subprocess.STDOUT,
33
  text=True
 
42
  <iframe src="{url}?token={token}" width="100%" height="600px" style="border: none;"></iframe>
43
  """
44
 
45
+ return "<p>❌ Failed to start LocalTunnel or retrieve its URL</p>"
46
 
47
  demo = gr.Interface(fn=launch_jupyter, inputs=[], outputs=gr.HTML())
48
  demo.launch()