Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,48 +1,49 @@
|
|
| 1 |
-
|
| 2 |
import subprocess
|
| 3 |
-
import
|
| 4 |
-
import
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
"
|
| 18 |
-
"--ip=
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
| 1 |
+
# run_jupyterlab.py
|
| 2 |
import subprocess
|
| 3 |
+
import sys
|
| 4 |
+
import os
|
| 5 |
+
import signal # For handling termination signals
|
| 6 |
+
|
| 7 |
+
def launch_jupyterlab():
|
| 8 |
+
"""Launches JupyterLab programmatically on port 7860 and waits for it to finish."""
|
| 9 |
+
print("Attempting to launch JupyterLab on port 7860...")
|
| 10 |
+
|
| 11 |
+
command = [
|
| 12 |
+
sys.executable,
|
| 13 |
+
"-m",
|
| 14 |
+
"jupyterlab",
|
| 15 |
+
"--no-browser", # Remove this line if you want it to open automatically in your browser
|
| 16 |
+
"--port",
|
| 17 |
+
"7860",
|
| 18 |
+
"--ip=0.0.0.0" # IMPORTANT: Make sure it listens on all interfaces inside the container
|
| 19 |
+
]
|
| 20 |
+
|
| 21 |
+
# Optional: Uncomment and modify if you want to specify a working directory
|
| 22 |
+
# command.extend(["--notebook-dir", "/path/to/your/notebooks"])
|
| 23 |
+
|
| 24 |
+
try:
|
| 25 |
+
print(f"Executing command: {' '.join(command)}")
|
| 26 |
+
# Use subprocess.Popen to run the command
|
| 27 |
+
process = subprocess.Popen(command)
|
| 28 |
+
|
| 29 |
+
print("\nJupyterLab launched! Check your terminal for the URL.")
|
| 30 |
+
print("You should see a URL like 'http://localhost:7860/lab?token=...'")
|
| 31 |
+
print("Copy and paste this URL into your web browser to access JupyterLab.")
|
| 32 |
+
print("Keep this terminal window open (or container running) while you are using JupyterLab.")
|
| 33 |
+
|
| 34 |
+
# --- IMPORTANT CHANGE HERE ---
|
| 35 |
+
# Wait for the JupyterLab process to terminate.
|
| 36 |
+
# This keeps the Python script (and thus the container's main process) alive.
|
| 37 |
+
print("\nWaiting for JupyterLab process to terminate...")
|
| 38 |
+
process.wait()
|
| 39 |
+
print("JupyterLab process terminated.")
|
| 40 |
+
|
| 41 |
+
except FileNotFoundError:
|
| 42 |
+
print("Error: 'jupyterlab' command not found.")
|
| 43 |
+
print("Please ensure JupyterLab is installed. You can install it with:")
|
| 44 |
+
print("pip install jupyterlab")
|
| 45 |
+
except Exception as e:
|
| 46 |
+
print(f"An error occurred while launching JupyterLab: {e}")
|
| 47 |
+
|
| 48 |
+
if __name__ == "__main__":
|
| 49 |
+
launch_jupyterlab()
|