Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,39 +1,47 @@
|
|
| 1 |
-
# run_jupyterlab.py
|
| 2 |
-
import subprocess
|
| 3 |
-
import sys
|
| 4 |
import os
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 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()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
+
import subprocess
|
| 3 |
+
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
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
for line in proc.stdout:
|
| 36 |
+
if "your url is:" in line:
|
| 37 |
+
url = line.strip().split("your url is:")[1].strip()
|
| 38 |
+
return f"""
|
| 39 |
+
<h3>✅ JupyterLab Running</h3>
|
| 40 |
+
<p>Public URL: <a href="{url}?token={token}" target="_blank">{url}?token={token}</a></p>
|
| 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()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|