Spaces:
Paused
Paused
fix
Browse files
app.py
CHANGED
@@ -3,20 +3,28 @@
|
|
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 |
-
|
11 |
log_file = "/home/user/app/app.log"
|
12 |
|
|
|
13 |
def install_packages():
|
14 |
-
#
|
15 |
with open(log_file, "a") as f:
|
16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
def configure_jupyter():
|
19 |
-
#
|
20 |
jupyter_config_dir = os.path.expanduser('~/.jupyter')
|
21 |
os.makedirs(jupyter_config_dir, exist_ok=True)
|
22 |
|
@@ -36,7 +44,7 @@ c.ServerApp.allow_root = True
|
|
36 |
""")
|
37 |
|
38 |
def start_jupyter():
|
39 |
-
#
|
40 |
with open(log_file, "a") as f:
|
41 |
subprocess.Popen(['jupyter-lab', '--port', '8888', '--autoreload'], stdout=f, stderr=f)
|
42 |
|
@@ -55,11 +63,10 @@ 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 |
-
#
|
63 |
WSGIRequestHandler.log_request = lambda self, *args, **kwargs: None
|
64 |
|
65 |
app.run(host='0.0.0.0', port=7860, debug=False)
|
|
|
3 |
|
4 |
import os
|
5 |
import subprocess
|
|
|
|
|
|
|
6 |
|
7 |
+
# Definir el archivo de log antes de instalar las bibliotecas
|
8 |
log_file = "/home/user/app/app.log"
|
9 |
|
10 |
+
# Instalar las bibliotecas necesarias
|
11 |
def install_packages():
|
12 |
+
# Instalar los paquetes necesarios si aún no están instalados
|
13 |
with open(log_file, "a") as f:
|
14 |
+
f.write("===== Installing Packages =====\n")
|
15 |
+
subprocess.run(['pip3', 'install', '--quiet', 'jupyterlab', 'flask', 'gradio'], check=True, stdout=f, stderr=f)
|
16 |
+
|
17 |
+
install_packages()
|
18 |
+
|
19 |
+
# Ahora importar las bibliotecas necesarias
|
20 |
+
from flask import Flask, redirect
|
21 |
+
import gradio as gr
|
22 |
+
from werkzeug.serving import WSGIRequestHandler
|
23 |
+
|
24 |
+
app = Flask(__name__)
|
25 |
|
26 |
def configure_jupyter():
|
27 |
+
# Generar la configuración de Jupyter
|
28 |
jupyter_config_dir = os.path.expanduser('~/.jupyter')
|
29 |
os.makedirs(jupyter_config_dir, exist_ok=True)
|
30 |
|
|
|
44 |
""")
|
45 |
|
46 |
def start_jupyter():
|
47 |
+
# Iniciar JupyterLab en el puerto 8888 con autoreload
|
48 |
with open(log_file, "a") as f:
|
49 |
subprocess.Popen(['jupyter-lab', '--port', '8888', '--autoreload'], stdout=f, stderr=f)
|
50 |
|
|
|
63 |
with open(log_file, "a") as f:
|
64 |
f.write("===== Application Startup at {0} =====\n".format(subprocess.run(['date'], capture_output=True, text=True).stdout))
|
65 |
|
|
|
66 |
configure_jupyter()
|
67 |
start_jupyter()
|
68 |
|
69 |
+
# Deshabilitar los logs para Flask
|
70 |
WSGIRequestHandler.log_request = lambda self, *args, **kwargs: None
|
71 |
|
72 |
app.run(host='0.0.0.0', port=7860, debug=False)
|