Bibek Mukherjee
commited on
Update src/frontend/app.py
Browse files- src/frontend/app.py +25 -2
src/frontend/app.py
CHANGED
|
@@ -13,6 +13,14 @@ import plotly.graph_objects as go
|
|
| 13 |
from datetime import datetime
|
| 14 |
import joblib
|
| 15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
def run_api():
|
| 17 |
subprocess.Popen(["python", "-m", "uvicorn", "src.api.main:app", "--host", "0.0.0.0", "--port", "8000"])
|
| 18 |
|
|
@@ -21,9 +29,24 @@ if "api_started" not in st.session_state:
|
|
| 21 |
threading.Thread(target=run_api).start()
|
| 22 |
st.session_state.api_started = True
|
| 23 |
st.success("Starting API... please wait a few seconds.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
-
#
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# Add the project root to the Python path
|
| 29 |
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
|
|
|
|
| 13 |
from datetime import datetime
|
| 14 |
import joblib
|
| 15 |
|
| 16 |
+
st.set_page_config(
|
| 17 |
+
page_title="AI Prediction Dashboard",
|
| 18 |
+
page_icon="🎯",
|
| 19 |
+
layout="wide",
|
| 20 |
+
initial_sidebar_state="expanded"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
# Function to start the API server
|
| 24 |
def run_api():
|
| 25 |
subprocess.Popen(["python", "-m", "uvicorn", "src.api.main:app", "--host", "0.0.0.0", "--port", "8000"])
|
| 26 |
|
|
|
|
| 29 |
threading.Thread(target=run_api).start()
|
| 30 |
st.session_state.api_started = True
|
| 31 |
st.success("Starting API... please wait a few seconds.")
|
| 32 |
+
|
| 33 |
+
# Wait a few seconds for server to start
|
| 34 |
+
time.sleep(15)
|
| 35 |
+
|
| 36 |
+
# Function to check if API is running
|
| 37 |
+
def is_api_running():
|
| 38 |
+
try:
|
| 39 |
+
response = requests.get("http://localhost:8000/health")
|
| 40 |
+
return response.status_code == 200
|
| 41 |
+
except:
|
| 42 |
+
return False
|
| 43 |
|
| 44 |
+
# Check API status
|
| 45 |
+
api_status = is_api_running()
|
| 46 |
+
if api_status:
|
| 47 |
+
st.sidebar.success("✅ API is running")
|
| 48 |
+
else:
|
| 49 |
+
st.sidebar.error("❌ API is not running. Please refresh the page.")
|
| 50 |
|
| 51 |
# Add the project root to the Python path
|
| 52 |
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')))
|