Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,45 @@
|
|
|
|
1 |
import subprocess
|
|
|
2 |
import gradio as gr
|
3 |
|
4 |
def launch_jupyter():
|
5 |
-
|
6 |
-
|
|
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
demo = gr.Interface(fn=launch_jupyter, inputs=[], outputs="text")
|
9 |
demo.launch()
|
|
|
1 |
+
import os
|
2 |
import subprocess
|
3 |
+
import time
|
4 |
import gradio as gr
|
5 |
|
6 |
def launch_jupyter():
|
7 |
+
# 1. Install Node.js and LocalTunnel (runtime, not Dockerfile)
|
8 |
+
os.system("apt-get update && apt-get install -y nodejs npm")
|
9 |
+
os.system("npm install -g localtunnel")
|
10 |
|
11 |
+
# 2. Set a secure token (you can change this or generate dynamically)
|
12 |
+
token = "letmein123"
|
13 |
+
|
14 |
+
# 3. Launch JupyterLab with token authentication
|
15 |
+
subprocess.Popen([
|
16 |
+
"jupyter", "lab",
|
17 |
+
"--ip=127.0.0.1",
|
18 |
+
"--port=8888",
|
19 |
+
"--no-browser",
|
20 |
+
f"--NotebookApp.token={token}",
|
21 |
+
"--NotebookApp.allow_origin='*'",
|
22 |
+
"--NotebookApp.allow_remote_access=True"
|
23 |
+
])
|
24 |
+
|
25 |
+
time.sleep(5) # Give Jupyter some time to boot
|
26 |
+
|
27 |
+
# 4. Start LocalTunnel to expose port 8888
|
28 |
+
proc = subprocess.Popen(
|
29 |
+
["lt", "--port", "8888", "--subdomain", "zyxciss-jlab"],
|
30 |
+
stdout=subprocess.PIPE,
|
31 |
+
stderr=subprocess.STDOUT,
|
32 |
+
text=True
|
33 |
+
)
|
34 |
+
|
35 |
+
# 5. Extract and return the LocalTunnel URL
|
36 |
+
for line in proc.stdout:
|
37 |
+
if "your url is:" in line:
|
38 |
+
url = line.strip().split("your url is:")[1].strip()
|
39 |
+
return f"🔓 Access JupyterLab here:\n{url}?token={token}"
|
40 |
+
|
41 |
+
return "❌ Failed to start LocalTunnel."
|
42 |
+
|
43 |
+
# Gradio UI
|
44 |
demo = gr.Interface(fn=launch_jupyter, inputs=[], outputs="text")
|
45 |
demo.launch()
|