File size: 1,656 Bytes
e1f4a7c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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)
    })