-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstart_system.py
More file actions
85 lines (69 loc) · 2.35 KB
/
start_system.py
File metadata and controls
85 lines (69 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python3
"""
Startup script for the complete RAG Chatbot system.
"""
import subprocess
import time
import sys
import signal
import os
from pathlib import Path
def start_api():
"""Start the API server."""
print("🚀 Starting API server...")
return subprocess.Popen([
sys.executable, "start_api.py"
], cwd=Path(__file__).parent)
def start_ui():
"""Start the UI server."""
print("🎨 Starting UI server...")
time.sleep(3) # Wait for API to start
return subprocess.Popen([
sys.executable, "start_ui.py"
], cwd=Path(__file__).parent)
def main():
"""Main startup function."""
print("🤖 RAG Chatbot System Startup")
print("=" * 40)
# Check if virtual environment is activated
if not hasattr(sys, 'real_prefix') and not (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix):
print("⚠️ Warning: Virtual environment not detected")
print(" Please run: source venv/bin/activate")
print(" Then run this script again")
return
api_process = None
ui_process = None
try:
# Start API
api_process = start_api()
# Start UI
ui_process = start_ui()
print("\n✅ System started successfully!")
print("📊 API Documentation: http://localhost:8000/docs")
print("🎨 Web Interface: http://localhost:7860")
print("\nPress Ctrl+C to stop both services")
# Wait for processes
while True:
time.sleep(1)
# Check if processes are still running
if api_process.poll() is not None:
print("❌ API process stopped unexpectedly")
break
if ui_process.poll() is not None:
print("❌ UI process stopped unexpectedly")
break
except KeyboardInterrupt:
print("\n🛑 Shutting down system...")
finally:
# Clean shutdown
if ui_process:
ui_process.terminate()
ui_process.wait()
print("✅ UI server stopped")
if api_process:
api_process.terminate()
api_process.wait()
print("✅ API server stopped")
print("👋 System shutdown complete")
if __name__ == "__main__":
main()