-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_all.py
More file actions
69 lines (55 loc) · 1.75 KB
/
run_all.py
File metadata and controls
69 lines (55 loc) · 1.75 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
"""
Script to run both the FastAPI backend and Streamlit UI.
Usage:
python run_all.py
This will start:
- FastAPI backend on http://localhost:8000
- Streamlit UI on http://localhost:8502
"""
import subprocess
import sys
import time
import webbrowser
from threading import Thread
from app.config import settings
BACKEND_API_SERVER_PORT = str(settings.api_port)
UI_APP_PORT = str(settings.ui_port)
def run_api():
"""Run the FastAPI backend."""
print(F"🚀 Starting FastAPI backend on http://localhost:{BACKEND_API_SERVER_PORT}")
subprocess.run([
sys.executable, "-m", "uvicorn",
"app.main:app",
"--host", "0.0.0.0",
"--port", BACKEND_API_SERVER_PORT,
"--reload"
])
def run_streamlit():
"""Run the Streamlit UI."""
print(F"🎨 Starting Streamlit UI on http://localhost:{UI_APP_PORT}")
subprocess.run([
sys.executable, "-m", "streamlit",
"run", "ui/app.py",
"--server.port", UI_APP_PORT,
"--server.headless", "true"
])
def open_browser():
"""Open browser after a delay."""
time.sleep(3)
print("\n🌐 Opening Streamlit UI in browser...")
webbrowser.open(F"http://localhost:{UI_APP_PORT}")
if __name__ == "__main__":
# Start API in a thread
api_thread = Thread(target=run_api, daemon=True)
api_thread.start()
# Wait for API to start
time.sleep(2)
# Open browser in background
browser_thread = Thread(target=open_browser, daemon=True)
browser_thread.start()
# Run Streamlit in main thread (blocking)
try:
run_streamlit()
except KeyboardInterrupt:
print("\n👋 Shutting down services...")
sys.exit(0)