J Z commited on
Commit
543ea03
·
verified ·
1 Parent(s): e233f2e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -54
app.py CHANGED
@@ -2,64 +2,25 @@ import os
2
  import sys
3
  import subprocess
4
  import time
5
- import signal
6
- import atexit
7
 
8
- # Add the DarwinChatbot scripts directory to the Python path
9
  DARWIN_SCRIPTS_PATH = "/data/DarwinChatbot/scripts"
10
- NICEGUI_PORT = 7860
11
-
12
- # Path to Ollama executable
13
  OLLAMA_PATH = "/data/DarwinChatbot/ollama"
14
 
15
- # Global process variables
16
- OLLAMA_PROCESS = None
17
- DARWIN_APP_PROCESS = None
 
 
 
18
 
19
- def cleanup():
20
- """Stop all processes on exit"""
21
- if DARWIN_APP_PROCESS:
22
- DARWIN_APP_PROCESS.terminate()
23
-
24
- if OLLAMA_PROCESS:
25
- OLLAMA_PROCESS.terminate()
26
 
27
- # Register cleanup handler
28
- atexit.register(cleanup)
29
- signal.signal(signal.SIGTERM, lambda sig, frame: cleanup())
30
- signal.signal(signal.SIGINT, lambda sig, frame: cleanup())
31
 
32
- if __name__ == "__main__":
33
- # 1. Start Ollama server
34
- print("Starting Ollama server...")
35
- OLLAMA_PROCESS = subprocess.Popen(
36
- [OLLAMA_PATH, "serve"],
37
- stdout=subprocess.DEVNULL,
38
- stderr=subprocess.DEVNULL
39
- )
40
-
41
- # Give Ollama a moment to start
42
- time.sleep(3)
43
-
44
- # 2. Start the Darwin app
45
- print("Starting Darwin Avatar app...")
46
- env = os.environ.copy()
47
- env["NICEGUI_PORT"] = str(NICEGUI_PORT)
48
- env["NICEGUI_HOST"] = "0.0.0.0"
49
-
50
- os.chdir(DARWIN_SCRIPTS_PATH)
51
- DARWIN_APP_PROCESS = subprocess.Popen(
52
- [sys.executable, "app.py"],
53
- env=env,
54
- cwd=DARWIN_SCRIPTS_PATH
55
- )
56
-
57
- print(f"Darwin Avatar is running on port {NICEGUI_PORT}")
58
-
59
- # 3. Keep the main process running
60
- try:
61
- DARWIN_APP_PROCESS.wait()
62
- except KeyboardInterrupt:
63
- pass
64
- finally:
65
- cleanup()
 
2
  import sys
3
  import subprocess
4
  import time
 
 
5
 
6
+ # Configure paths
7
  DARWIN_SCRIPTS_PATH = "/data/DarwinChatbot/scripts"
 
 
 
8
  OLLAMA_PATH = "/data/DarwinChatbot/ollama"
9
 
10
+ # Start Ollama in background using basic shell command
11
+ print("Starting Ollama server...")
12
+ subprocess.run(f"{OLLAMA_PATH} serve &", shell=True)
13
+
14
+ # Wait a moment for Ollama to initialize
15
+ time.sleep(3)
16
 
17
+ # Configure environment for NiceGUI
18
+ os.environ["NICEGUI_PORT"] = "7860"
19
+ os.environ["NICEGUI_HOST"] = "0.0.0.0"
 
 
 
 
20
 
21
+ # Change to the DarwinChatbot scripts directory
22
+ os.chdir(DARWIN_SCRIPTS_PATH)
 
 
23
 
24
+ # Execute app.py directly
25
+ print("Starting Darwin Avatar app...")
26
+ exec(open("app.py").read())