Spaces:
Paused
Paused
gradio y jupy
Browse files
app.py
CHANGED
|
@@ -3,10 +3,14 @@
|
|
| 3 |
|
| 4 |
import os
|
| 5 |
import subprocess
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
def install_packages():
|
| 8 |
# Install necessary packages
|
| 9 |
-
subprocess.run(['pip3', 'install', 'jupyterlab'], check=True)
|
| 10 |
|
| 11 |
def configure_jupyter():
|
| 12 |
# Generate Jupyter configuration
|
|
@@ -14,20 +18,37 @@ def configure_jupyter():
|
|
| 14 |
os.makedirs(jupyter_config_dir, exist_ok=True)
|
| 15 |
|
| 16 |
config_file = os.path.join(jupyter_config_dir, 'jupyter_lab_config.py')
|
|
|
|
|
|
|
|
|
|
| 17 |
with open(config_file, 'w') as f:
|
| 18 |
f.write(f"""
|
| 19 |
c.ServerApp.ip = '0.0.0.0'
|
| 20 |
-
c.ServerApp.port =
|
| 21 |
c.ServerApp.open_browser = False
|
| 22 |
-
|
| 23 |
c.ServerApp.root_dir = '/home/user/app'
|
|
|
|
|
|
|
| 24 |
""")
|
| 25 |
|
| 26 |
def start_jupyter():
|
| 27 |
-
# Start JupyterLab
|
| 28 |
-
subprocess.run(['jupyter-lab --autoreload'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
if __name__ == "__main__":
|
| 31 |
install_packages()
|
| 32 |
configure_jupyter()
|
| 33 |
-
|
|
|
|
|
|
| 3 |
|
| 4 |
import os
|
| 5 |
import subprocess
|
| 6 |
+
from flask import Flask, redirect, request
|
| 7 |
+
import gradio as gr
|
| 8 |
+
|
| 9 |
+
app = Flask(__name__)
|
| 10 |
|
| 11 |
def install_packages():
|
| 12 |
# Install necessary packages
|
| 13 |
+
subprocess.run(['pip3', 'install', 'jupyterlab', 'flask', 'gradio'], check=True)
|
| 14 |
|
| 15 |
def configure_jupyter():
|
| 16 |
# Generate Jupyter configuration
|
|
|
|
| 18 |
os.makedirs(jupyter_config_dir, exist_ok=True)
|
| 19 |
|
| 20 |
config_file = os.path.join(jupyter_config_dir, 'jupyter_lab_config.py')
|
| 21 |
+
jupyter_password = os.environ.get('JUPYPASS', '')
|
| 22 |
+
password_config = f"c.ServerApp.password = u'{jupyter_password}'" if jupyter_password else ''
|
| 23 |
+
|
| 24 |
with open(config_file, 'w') as f:
|
| 25 |
f.write(f"""
|
| 26 |
c.ServerApp.ip = '0.0.0.0'
|
| 27 |
+
c.ServerApp.port = 8888
|
| 28 |
c.ServerApp.open_browser = False
|
| 29 |
+
{password_config}
|
| 30 |
c.ServerApp.root_dir = '/home/user/app'
|
| 31 |
+
c.ServerApp.terminado_settings = {{'shell_command': ['bash']}}
|
| 32 |
+
c.ServerApp.allow_root = True
|
| 33 |
""")
|
| 34 |
|
| 35 |
def start_jupyter():
|
| 36 |
+
# Start JupyterLab on port 8888 with autoreload
|
| 37 |
+
subprocess.run(['jupyter-lab', '--port', '8888', '--autoreload'])
|
| 38 |
+
|
| 39 |
+
@app.route('/')
|
| 40 |
+
def home():
|
| 41 |
+
def greet(name):
|
| 42 |
+
return f"Hello {name}!"
|
| 43 |
+
iface = gr.Interface(fn=greet, inputs="text", outputs="text")
|
| 44 |
+
return iface.launch(inline=True)
|
| 45 |
+
|
| 46 |
+
@app.route('/lab')
|
| 47 |
+
def lab():
|
| 48 |
+
return redirect("http://localhost:8888", code=302)
|
| 49 |
|
| 50 |
if __name__ == "__main__":
|
| 51 |
install_packages()
|
| 52 |
configure_jupyter()
|
| 53 |
+
subprocess.Popen(start_jupyter)
|
| 54 |
+
app.run(host='0.0.0.0', port=7860)
|