Spaces:
Paused
Paused
fixed
Browse files- app.py +17 -6
- requirements.txt +4 -0
app.py
CHANGED
|
@@ -3,14 +3,17 @@
|
|
| 3 |
|
| 4 |
import os
|
| 5 |
import subprocess
|
| 6 |
-
from flask import Flask, redirect
|
| 7 |
import gradio as gr
|
|
|
|
| 8 |
|
| 9 |
app = Flask(__name__)
|
|
|
|
| 10 |
|
| 11 |
def install_packages():
|
| 12 |
-
# Install necessary packages
|
| 13 |
-
|
|
|
|
| 14 |
|
| 15 |
def configure_jupyter():
|
| 16 |
# Generate Jupyter configuration
|
|
@@ -34,7 +37,8 @@ c.ServerApp.allow_root = True
|
|
| 34 |
|
| 35 |
def start_jupyter():
|
| 36 |
# Start JupyterLab on port 8888 with autoreload
|
| 37 |
-
|
|
|
|
| 38 |
|
| 39 |
@app.route('/')
|
| 40 |
def home():
|
|
@@ -48,7 +52,14 @@ def lab():
|
|
| 48 |
return redirect("http://localhost:8888", code=302)
|
| 49 |
|
| 50 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
| 51 |
install_packages()
|
| 52 |
configure_jupyter()
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
import os
|
| 5 |
import subprocess
|
| 6 |
+
from flask import Flask, redirect
|
| 7 |
import gradio as gr
|
| 8 |
+
from werkzeug.serving import WSGIRequestHandler
|
| 9 |
|
| 10 |
app = Flask(__name__)
|
| 11 |
+
log_file = "/home/user/app/app.log"
|
| 12 |
|
| 13 |
def install_packages():
|
| 14 |
+
# Install necessary packages if they are not already installed
|
| 15 |
+
with open(log_file, "a") as f:
|
| 16 |
+
subprocess.run(['pip3', 'install', '--quiet', 'jupyterlab', 'flask', 'gradio'], check=True)
|
| 17 |
|
| 18 |
def configure_jupyter():
|
| 19 |
# Generate Jupyter configuration
|
|
|
|
| 37 |
|
| 38 |
def start_jupyter():
|
| 39 |
# Start JupyterLab on port 8888 with autoreload
|
| 40 |
+
with open(log_file, "a") as f:
|
| 41 |
+
subprocess.Popen(['jupyter-lab', '--port', '8888', '--autoreload'], stdout=f, stderr=f)
|
| 42 |
|
| 43 |
@app.route('/')
|
| 44 |
def home():
|
|
|
|
| 52 |
return redirect("http://localhost:8888", code=302)
|
| 53 |
|
| 54 |
if __name__ == "__main__":
|
| 55 |
+
with open(log_file, "a") as f:
|
| 56 |
+
f.write("===== Application Startup at {0} =====\n".format(subprocess.run(['date'], capture_output=True, text=True).stdout))
|
| 57 |
+
|
| 58 |
install_packages()
|
| 59 |
configure_jupyter()
|
| 60 |
+
start_jupyter()
|
| 61 |
+
|
| 62 |
+
# Disable logging for Flask
|
| 63 |
+
WSGIRequestHandler.log_request = lambda self, *args, **kwargs: None
|
| 64 |
+
|
| 65 |
+
app.run(host='0.0.0.0', port=7860, debug=False)
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
flask
|
| 2 |
+
gradio
|
| 3 |
+
jupyterlab
|
| 4 |
+
werkzeug
|