ffbeqwbe commited on
Commit ·
b0cfcf1
1
Parent(s): c030b09
gradio
Browse files
app.py
CHANGED
|
@@ -3,17 +3,36 @@ import subprocess
|
|
| 3 |
import sys
|
| 4 |
import time
|
| 5 |
|
| 6 |
-
# Path to your main application
|
| 7 |
DARWIN_APP_PATH = "/data/DarwinChatbot"
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
def run_nicegui_app():
|
| 11 |
"""Run the NiceGUI app directly on port 7860"""
|
| 12 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
sys.path.insert(0, DARWIN_APP_PATH)
|
|
|
|
| 14 |
|
| 15 |
-
# Change to the
|
| 16 |
-
os.chdir(
|
| 17 |
|
| 18 |
# Set environment variables for the NiceGUI app
|
| 19 |
env = {
|
|
@@ -24,35 +43,18 @@ def run_nicegui_app():
|
|
| 24 |
"NICEGUI_NO_AUTO_RELOAD": "1" # Also try this environment variable
|
| 25 |
}
|
| 26 |
|
| 27 |
-
#
|
| 28 |
try:
|
| 29 |
-
print("[SPACES]
|
| 30 |
-
subprocess.check_call([sys.executable, "-m", "pip", "install", "flask==2.0.1"])
|
| 31 |
-
print("[SPACES] Flask installed/verified successfully")
|
| 32 |
-
except Exception as e:
|
| 33 |
-
print(f"[SPACES] Warning: Could not install Flask: {e}")
|
| 34 |
-
|
| 35 |
-
# Start the NiceGUI application with direct script execution
|
| 36 |
-
try:
|
| 37 |
-
print(f"[SPACES] Starting NiceGUI app directly from: {DARWIN_SCRIPT_PATH}")
|
| 38 |
-
|
| 39 |
-
# Verify the script exists
|
| 40 |
-
if not os.path.exists(DARWIN_SCRIPT_PATH):
|
| 41 |
-
print(f"[SPACES] ERROR: Script not found at {DARWIN_SCRIPT_PATH}")
|
| 42 |
-
print("[SPACES] Available directories:")
|
| 43 |
-
print(os.listdir(DARWIN_APP_PATH))
|
| 44 |
-
if os.path.exists(os.path.join(DARWIN_APP_PATH, "scripts")):
|
| 45 |
-
print("[SPACES] Files in scripts directory:")
|
| 46 |
-
print(os.listdir(os.path.join(DARWIN_APP_PATH, "scripts")))
|
| 47 |
-
return
|
| 48 |
|
| 49 |
-
#
|
| 50 |
process = subprocess.Popen(
|
| 51 |
-
[sys.executable,
|
| 52 |
stdout=subprocess.PIPE,
|
| 53 |
stderr=subprocess.STDOUT,
|
| 54 |
text=True,
|
| 55 |
-
env=env
|
|
|
|
| 56 |
)
|
| 57 |
|
| 58 |
print("[SPACES] Started NiceGUI app process")
|
|
@@ -61,9 +63,9 @@ def run_nicegui_app():
|
|
| 61 |
while True:
|
| 62 |
output = process.stdout.readline()
|
| 63 |
if output:
|
| 64 |
-
print(f"[
|
| 65 |
if process.poll() is not None:
|
| 66 |
-
print("[SPACES]
|
| 67 |
break
|
| 68 |
except Exception as e:
|
| 69 |
print(f"[SPACES] Error starting NiceGUI app: {e}")
|
|
@@ -71,12 +73,11 @@ def run_nicegui_app():
|
|
| 71 |
if __name__ == "__main__":
|
| 72 |
print("[SPACES] Starting Darwin Chatbot application")
|
| 73 |
|
| 74 |
-
# Start
|
| 75 |
-
# This will keep the script running and output logs
|
| 76 |
run_nicegui_app()
|
| 77 |
|
| 78 |
-
# If the
|
| 79 |
-
print("[SPACES]
|
| 80 |
while True:
|
| 81 |
time.sleep(60)
|
| 82 |
print("[SPACES] Container still running, waiting for restart...")
|
|
|
|
| 3 |
import sys
|
| 4 |
import time
|
| 5 |
|
| 6 |
+
# Path to your main application - CORRECT PATH
|
| 7 |
DARWIN_APP_PATH = "/data/DarwinChatbot"
|
| 8 |
+
SCRIPT_DIR = os.path.join(DARWIN_APP_PATH, "scripts")
|
| 9 |
+
SCRIPT_PATH = os.path.join(SCRIPT_DIR, "app.py")
|
| 10 |
|
| 11 |
def run_nicegui_app():
|
| 12 |
"""Run the NiceGUI app directly on port 7860"""
|
| 13 |
+
# Check if the script exists first
|
| 14 |
+
if not os.path.exists(SCRIPT_PATH):
|
| 15 |
+
print(f"[SPACES] ERROR: Script not found at {SCRIPT_PATH}")
|
| 16 |
+
print("[SPACES] Listing available files:")
|
| 17 |
+
|
| 18 |
+
# List files in the main directory
|
| 19 |
+
print(f"Files in {DARWIN_APP_PATH}:")
|
| 20 |
+
if os.path.exists(DARWIN_APP_PATH):
|
| 21 |
+
print(os.listdir(DARWIN_APP_PATH))
|
| 22 |
+
|
| 23 |
+
# List files in the scripts directory if it exists
|
| 24 |
+
print(f"Files in {SCRIPT_DIR}:")
|
| 25 |
+
if os.path.exists(SCRIPT_DIR):
|
| 26 |
+
print(os.listdir(SCRIPT_DIR))
|
| 27 |
+
|
| 28 |
+
return
|
| 29 |
+
|
| 30 |
+
# Add the paths to Python path
|
| 31 |
sys.path.insert(0, DARWIN_APP_PATH)
|
| 32 |
+
sys.path.insert(0, SCRIPT_DIR)
|
| 33 |
|
| 34 |
+
# Change to the scripts directory to ensure imports work correctly
|
| 35 |
+
os.chdir(SCRIPT_DIR)
|
| 36 |
|
| 37 |
# Set environment variables for the NiceGUI app
|
| 38 |
env = {
|
|
|
|
| 43 |
"NICEGUI_NO_AUTO_RELOAD": "1" # Also try this environment variable
|
| 44 |
}
|
| 45 |
|
| 46 |
+
# Start the NiceGUI application
|
| 47 |
try:
|
| 48 |
+
print(f"[SPACES] Starting NiceGUI app from {SCRIPT_PATH}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
+
# Directly run the script from the scripts directory
|
| 51 |
process = subprocess.Popen(
|
| 52 |
+
[sys.executable, SCRIPT_PATH],
|
| 53 |
stdout=subprocess.PIPE,
|
| 54 |
stderr=subprocess.STDOUT,
|
| 55 |
text=True,
|
| 56 |
+
env=env,
|
| 57 |
+
cwd=SCRIPT_DIR # Set the working directory explicitly
|
| 58 |
)
|
| 59 |
|
| 60 |
print("[SPACES] Started NiceGUI app process")
|
|
|
|
| 63 |
while True:
|
| 64 |
output = process.stdout.readline()
|
| 65 |
if output:
|
| 66 |
+
print(f"[APP] {output.strip()}")
|
| 67 |
if process.poll() is not None:
|
| 68 |
+
print("[SPACES] Process exited with code:", process.returncode)
|
| 69 |
break
|
| 70 |
except Exception as e:
|
| 71 |
print(f"[SPACES] Error starting NiceGUI app: {e}")
|
|
|
|
| 73 |
if __name__ == "__main__":
|
| 74 |
print("[SPACES] Starting Darwin Chatbot application")
|
| 75 |
|
| 76 |
+
# Start the app in the main thread
|
|
|
|
| 77 |
run_nicegui_app()
|
| 78 |
|
| 79 |
+
# If the app exits, keep the process alive
|
| 80 |
+
print("[SPACES] App exited, keeping container alive")
|
| 81 |
while True:
|
| 82 |
time.sleep(60)
|
| 83 |
print("[SPACES] Container still running, waiting for restart...")
|