zyxciss commited on
Commit
9445a1b
·
verified ·
1 Parent(s): f5f6658

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -43
app.py CHANGED
@@ -1,45 +1,39 @@
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()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # run_jupyterlab.py
2
  import subprocess
3
+ import sys
4
+ import os
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5
 
6
+ def launch_jupyterlab():
7
+ """Launches JupyterLab programmatically on port 7860."""
8
+ print("Attempting to launch JupyterLab on port 7860...")
9
+
10
+ command = [
11
+ sys.executable,
12
+ "-m",
13
+ "jupyterlab",
14
+ "--no-browser", # Remove this line if you want it to open automatically in your browser
15
+ "--port",
16
+ "7860" # Changed the port to 7860 as requested
17
+ ]
18
+
19
+ # Optional: Uncomment and modify if you want to specify a working directory
20
+ # command.extend(["--notebook-dir", "/path/to/your/notebooks"])
21
+
22
+ try:
23
+ print(f"Executing command: {' '.join(command)}")
24
+ process = subprocess.Popen(command)
25
+
26
+ print("\nJupyterLab launched! Check your terminal for the URL.")
27
+ print("You should see a URL like 'http://localhost:7860/lab?token=...'")
28
+ print("Copy and paste this URL into your web browser to access JupyterLab.")
29
+ print("Keep this terminal window open while you are using JupyterLab.")
30
+
31
+ except FileNotFoundError:
32
+ print("Error: 'jupyterlab' command not found.")
33
+ print("Please ensure JupyterLab is installed. You can install it with:")
34
+ print("pip install jupyterlab")
35
+ except Exception as e:
36
+ print(f"An error occurred while launching JupyterLab: {e}")
37
+
38
+ if __name__ == "__main__":
39
+ launch_jupyterlab()