Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import numpy as np | |
| import pandas as pd | |
| import joblib | |
| import matplotlib.pyplot as plt | |
| import seaborn as sns | |
| from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay | |
| # Load model | |
| model = joblib.load("random_forest_model.pkl") | |
| # Page configuration | |
| st.set_page_config(page_title="Sleep Detector ", layout="wide") | |
| # Custom CSS | |
| st.markdown(""" | |
| <style> | |
| .main { | |
| background-color: #f4f6f9; | |
| font-family: 'Segoe UI', sans-serif; | |
| } | |
| h1, h2, h3 { | |
| color: #333; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| st.title("π΄ AI Sleep Detection System") | |
| st.markdown("Navigate the Sleep Detection project through each CRISP-ML(Q) step.") | |
| st.header("π€ Model Prediction") | |
| angle = st.number_input("π Enter Angle (0β360Β°)", 0.0, 360.0, step=0.1) | |
| enmo = st.number_input("π Enter ENMO (0.0000β10.0000)", 0.0, 10.0, step=0.0001, format="%.4f") | |
| if st.button("π Predict Sleep State"): | |
| input_data = np.array([[angle, enmo]]) | |
| prediction = model.predict(input_data)[0] | |
| confidence = model.predict_proba(input_data)[0][prediction] * 100 | |
| label = "π Wakeup" if prediction == 0 else "π Sleep Onset" | |
| color = "#ffcc00" if prediction == 0 else "#6699ff" | |
| st.markdown(f"<h3 style='color:{color}'>π§ Prediction: {label}</h3>", unsafe_allow_html=True) | |
| st.markdown(f"**Confidence Score:** `{confidence:.2f}%`") | |
| st.subheader("π Input Summary") | |
| st.json({ | |
| "Angle": round(angle, 2), | |
| "ENMO": round(enmo, 4), | |
| "Predicted State": "Wakeup" if prediction == 0 else "Sleep Onset", | |
| "Confidence (%)": round(confidence, 2) | |
| }) | |