Spaces:
Paused
Paused
fix
Browse files
app.py
CHANGED
@@ -3,6 +3,7 @@
|
|
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"
|
@@ -12,7 +13,7 @@ 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'
|
16 |
|
17 |
install_packages()
|
18 |
|
@@ -43,16 +44,21 @@ c.ServerApp.terminado_settings = {{'shell_command': ['bash']}}
|
|
43 |
c.ServerApp.allow_root = True
|
44 |
""")
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
def start_jupyter():
|
47 |
-
# Iniciar JupyterLab en el puerto 8898 con autoreload
|
48 |
-
|
49 |
-
|
|
|
50 |
|
51 |
@app.route('/')
|
52 |
def home():
|
53 |
-
import spaces
|
54 |
-
|
55 |
-
@spaces.GPU(duration=150)
|
56 |
def greet(name):
|
57 |
return f"Hello {name}!"
|
58 |
|
|
|
3 |
|
4 |
import os
|
5 |
import subprocess
|
6 |
+
import psutil
|
7 |
|
8 |
# Definir el archivo de log antes de instalar las bibliotecas
|
9 |
log_file = "/home/user/app/app.log"
|
|
|
13 |
# Instalar los paquetes necesarios si a煤n no est谩n instalados
|
14 |
with open(log_file, "a") as f:
|
15 |
f.write("===== Installing Packages =====\n")
|
16 |
+
subprocess.run(['pip3', 'install', '--quiet', 'jupyterlab', 'flask', 'gradio'], check=True, stdout=f, stderr=f)
|
17 |
|
18 |
install_packages()
|
19 |
|
|
|
44 |
c.ServerApp.allow_root = True
|
45 |
""")
|
46 |
|
47 |
+
def is_jupyter_running():
|
48 |
+
# Verificar si JupyterLab ya est谩 en ejecuci贸n
|
49 |
+
for process in psutil.process_iter(['pid', 'name']):
|
50 |
+
if 'jupyter-lab' in process.info['name']:
|
51 |
+
return True
|
52 |
+
return False
|
53 |
+
|
54 |
def start_jupyter():
|
55 |
+
# Iniciar JupyterLab en el puerto 8898 con autoreload si no est谩 en ejecuci贸n
|
56 |
+
if not is_jupyter_running():
|
57 |
+
with open(log_file, "a") as f:
|
58 |
+
subprocess.Popen(['jupyter-lab', '--port', '8898', '--autoreload'], stdout=f, stderr=f)
|
59 |
|
60 |
@app.route('/')
|
61 |
def home():
|
|
|
|
|
|
|
62 |
def greet(name):
|
63 |
return f"Hello {name}!"
|
64 |
|