prahalya commited on
Commit
e1f4a7c
Β·
verified Β·
1 Parent(s): 953c325

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+ import pandas as pd
4
+ import joblib
5
+ import matplotlib.pyplot as plt
6
+ import seaborn as sns
7
+ from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay
8
+
9
+ # Load model
10
+ model = joblib.load("random_forest_model.pkl")
11
+
12
+ # Page configuration
13
+ st.set_page_config(page_title="Sleep Detector ", layout="wide")
14
+
15
+ # Custom CSS
16
+ st.markdown("""
17
+ <style>
18
+ .main {
19
+ background-color: #f4f6f9;
20
+ font-family: 'Segoe UI', sans-serif;
21
+ }
22
+ h1, h2, h3 {
23
+ color: #333;
24
+ }
25
+ </style>
26
+ """, unsafe_allow_html=True)
27
+
28
+ st.title("😴 AI Sleep Detection System")
29
+ st.markdown("Navigate the Sleep Detection project through each CRISP-ML(Q) step.")
30
+
31
+ st.header("πŸ€– Model Prediction")
32
+
33
+ angle = st.number_input("πŸ“ Enter Angle (0–360Β°)", 0.0, 360.0, step=0.1)
34
+ enmo = st.number_input("πŸ“Š Enter ENMO (0.0000–10.0000)", 0.0, 10.0, step=0.0001, format="%.4f")
35
+
36
+ if st.button("πŸ” Predict Sleep State"):
37
+ input_data = np.array([[angle, enmo]])
38
+ prediction = model.predict(input_data)[0]
39
+ confidence = model.predict_proba(input_data)[0][prediction] * 100
40
+
41
+ label = "🌞 Wakeup" if prediction == 0 else "πŸŒ™ Sleep Onset"
42
+ color = "#ffcc00" if prediction == 0 else "#6699ff"
43
+
44
+ st.markdown(f"<h3 style='color:{color}'>🧠 Prediction: {label}</h3>", unsafe_allow_html=True)
45
+ st.markdown(f"**Confidence Score:** `{confidence:.2f}%`")
46
+
47
+ st.subheader("πŸ“‹ Input Summary")
48
+ st.json({
49
+ "Angle": round(angle, 2),
50
+ "ENMO": round(enmo, 4),
51
+ "Predicted State": "Wakeup" if prediction == 0 else "Sleep Onset",
52
+ "Confidence (%)": round(confidence, 2)
53
+ })