ffbeqwbe commited on
Commit ·
4d10a9f
1
Parent(s): 33896d9
gradio fix
Browse files- app.py +20 -38
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -9,43 +9,25 @@ import time
|
|
| 9 |
DARWIN_APP_PATH = "/data/DarwinChatbot"
|
| 10 |
DARWIN_SCRIPT_PATH = os.path.join(DARWIN_APP_PATH, "scripts", "app.py")
|
| 11 |
|
| 12 |
-
def run_ollama_serve():
|
| 13 |
-
"""Start Ollama’s local inference server."""
|
| 14 |
-
try:
|
| 15 |
-
print("[SPACES] Starting Ollama serve...")
|
| 16 |
-
# Launch ollama serve (will keep running)
|
| 17 |
-
proc = subprocess.Popen(
|
| 18 |
-
["ollama", "serve"],
|
| 19 |
-
stdout=subprocess.PIPE,
|
| 20 |
-
stderr=subprocess.STDOUT,
|
| 21 |
-
text=True,
|
| 22 |
-
env=os.environ
|
| 23 |
-
)
|
| 24 |
-
# Optionally log Ollama output
|
| 25 |
-
while True:
|
| 26 |
-
line = proc.stdout.readline()
|
| 27 |
-
if not line and proc.poll() is not None:
|
| 28 |
-
break
|
| 29 |
-
if line:
|
| 30 |
-
print(f"[OLLAMA] {line.strip()}")
|
| 31 |
-
print("[SPACES] Ollama serve exited with code", proc.returncode)
|
| 32 |
-
except Exception as e:
|
| 33 |
-
print(f"[SPACES] Error launching Ollama serve: {e}")
|
| 34 |
-
|
| 35 |
def run_nicegui_app():
|
| 36 |
-
"""Run the NiceGUI app directly on port 7860
|
| 37 |
# Add the Darwin app path to Python path
|
| 38 |
sys.path.insert(0, DARWIN_APP_PATH)
|
|
|
|
| 39 |
# Change to the app directory
|
| 40 |
os.chdir(DARWIN_APP_PATH)
|
|
|
|
| 41 |
# Set environment variables for the NiceGUI app
|
| 42 |
env = {
|
| 43 |
-
**os.environ,
|
| 44 |
-
"PORT": "7860",
|
| 45 |
-
"HOST": "0.0.0.0"
|
| 46 |
}
|
|
|
|
|
|
|
| 47 |
try:
|
| 48 |
print(f"[SPACES] Starting NiceGUI app from {DARWIN_SCRIPT_PATH}")
|
|
|
|
| 49 |
# Verify the script exists
|
| 50 |
if not os.path.exists(DARWIN_SCRIPT_PATH):
|
| 51 |
print(f"[SPACES] ERROR: Script not found at {DARWIN_SCRIPT_PATH}")
|
|
@@ -56,7 +38,7 @@ def run_nicegui_app():
|
|
| 56 |
else:
|
| 57 |
print(f"[SPACES] Scripts directory not found at {scripts_dir}")
|
| 58 |
return
|
| 59 |
-
|
| 60 |
process = subprocess.Popen(
|
| 61 |
[sys.executable, DARWIN_SCRIPT_PATH],
|
| 62 |
stdout=subprocess.PIPE,
|
|
@@ -64,7 +46,9 @@ def run_nicegui_app():
|
|
| 64 |
text=True,
|
| 65 |
env=env
|
| 66 |
)
|
|
|
|
| 67 |
print("[SPACES] Started NiceGUI app process")
|
|
|
|
| 68 |
# Log output from the NiceGUI app
|
| 69 |
while True:
|
| 70 |
output = process.stdout.readline()
|
|
@@ -77,17 +61,15 @@ def run_nicegui_app():
|
|
| 77 |
print(f"[SPACES] Error starting NiceGUI app: {e}")
|
| 78 |
|
| 79 |
if __name__ == "__main__":
|
| 80 |
-
print("[SPACES]
|
| 81 |
-
|
| 82 |
-
#
|
| 83 |
-
|
| 84 |
-
ollama_thread.start()
|
| 85 |
-
|
| 86 |
-
# 2) Then start the NiceGUI frontend (blocks until exit)
|
| 87 |
run_nicegui_app()
|
| 88 |
-
|
| 89 |
-
# If the NiceGUI app
|
|
|
|
| 90 |
print("[SPACES] NiceGUI app exited, keeping container alive")
|
| 91 |
while True:
|
| 92 |
time.sleep(60)
|
| 93 |
-
print("[SPACES] Container still running, waiting for restart...")
|
|
|
|
| 9 |
DARWIN_APP_PATH = "/data/DarwinChatbot"
|
| 10 |
DARWIN_SCRIPT_PATH = os.path.join(DARWIN_APP_PATH, "scripts", "app.py")
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
def run_nicegui_app():
|
| 13 |
+
"""Run the NiceGUI app directly on port 7860"""
|
| 14 |
# Add the Darwin app path to Python path
|
| 15 |
sys.path.insert(0, DARWIN_APP_PATH)
|
| 16 |
+
|
| 17 |
# Change to the app directory
|
| 18 |
os.chdir(DARWIN_APP_PATH)
|
| 19 |
+
|
| 20 |
# Set environment variables for the NiceGUI app
|
| 21 |
env = {
|
| 22 |
+
**os.environ,
|
| 23 |
+
"PORT": "7860", # Use the Hugging Face Spaces port directly
|
| 24 |
+
"HOST": "0.0.0.0" # Listen on all interfaces
|
| 25 |
}
|
| 26 |
+
|
| 27 |
+
# Start the NiceGUI application
|
| 28 |
try:
|
| 29 |
print(f"[SPACES] Starting NiceGUI app from {DARWIN_SCRIPT_PATH}")
|
| 30 |
+
|
| 31 |
# Verify the script exists
|
| 32 |
if not os.path.exists(DARWIN_SCRIPT_PATH):
|
| 33 |
print(f"[SPACES] ERROR: Script not found at {DARWIN_SCRIPT_PATH}")
|
|
|
|
| 38 |
else:
|
| 39 |
print(f"[SPACES] Scripts directory not found at {scripts_dir}")
|
| 40 |
return
|
| 41 |
+
|
| 42 |
process = subprocess.Popen(
|
| 43 |
[sys.executable, DARWIN_SCRIPT_PATH],
|
| 44 |
stdout=subprocess.PIPE,
|
|
|
|
| 46 |
text=True,
|
| 47 |
env=env
|
| 48 |
)
|
| 49 |
+
|
| 50 |
print("[SPACES] Started NiceGUI app process")
|
| 51 |
+
|
| 52 |
# Log output from the NiceGUI app
|
| 53 |
while True:
|
| 54 |
output = process.stdout.readline()
|
|
|
|
| 61 |
print(f"[SPACES] Error starting NiceGUI app: {e}")
|
| 62 |
|
| 63 |
if __name__ == "__main__":
|
| 64 |
+
print("[SPACES] Starting Darwin Chatbot application")
|
| 65 |
+
|
| 66 |
+
# Start NiceGUI in the main thread
|
| 67 |
+
# This will keep the script running and output logs
|
|
|
|
|
|
|
|
|
|
| 68 |
run_nicegui_app()
|
| 69 |
+
|
| 70 |
+
# If the NiceGUI app exits, keep the process alive
|
| 71 |
+
# (This should rarely happen unless there's an error)
|
| 72 |
print("[SPACES] NiceGUI app exited, keeping container alive")
|
| 73 |
while True:
|
| 74 |
time.sleep(60)
|
| 75 |
+
print("[SPACES] Container still running, waiting for restart...")
|
requirements.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
flask==2.0.1
|
| 2 |
nicegui>=1.3.8
|
| 3 |
gradio>=3.50.0
|
| 4 |
-
ollama
|
|
|
|
| 1 |
flask==2.0.1
|
| 2 |
nicegui>=1.3.8
|
| 3 |
gradio>=3.50.0
|
| 4 |
+
ollama
|