prahalya's picture
Create app.py
e1f4a7c verified
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)
})