zoya23 commited on
Commit
a87a892
·
verified ·
1 Parent(s): f3a7e8e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -30
app.py CHANGED
@@ -1,37 +1,21 @@
1
  import streamlit as st
2
- import pandas as pd
3
- import joblib
4
 
5
- # Load model
6
- model = joblib.load("log_reg_model.pkl") # or log_reg_model.pkl
7
 
8
- st.title("Sleep State Prediction App")
 
9
 
10
- # Upload test data
11
- uploaded_file = st.file_uploader("Upload test_series.parquet", type=["parquet"])
12
- if uploaded_file is not None:
13
- test_df = pd.read_parquet(uploaded_file)
14
- st.write("Sample of uploaded data:")
15
- st.dataframe(test_df.head())
16
 
17
- # Check if required columns exist
18
- if {'series_id', 'step', 'hour'}.issubset(test_df.columns):
19
- # Predict sleep state
20
- features = test_df[['step', 'hour']]
21
- predictions = model.predict(features)
22
-
23
- # Build submission-like DataFrame
24
- test_df = test_df.reset_index(drop=True)
25
- test_df["event"] = predictions
26
- test_df["row_id"] = test_df["series_id"] + "_" + test_df.index.astype(str)
27
- submission = test_df[["row_id", "event"]]
28
-
29
- st.success("Predictions completed.")
30
- st.write(submission.head())
31
-
32
- # Option to download
33
- csv = submission.to_csv(index=False).encode('utf-8')
34
- st.download_button("Download submission.csv", csv, "submission.csv", "text/csv")
35
 
 
 
36
  else:
37
- st.error("Uploaded file must contain 'series_id', 'step', and 'hour' columns.")
 
1
  import streamlit as st
2
+ import numpy as np
3
+ import joblib # use joblib instead of pickle
4
 
5
+ # Load model with joblib
6
+ model = joblib.load("log_reg_model.pkl")
7
 
8
+ st.title("AI Sleep State Detection")
9
+ st.markdown("Enter **angle** and **enmo** to predict the sleep state:")
10
 
11
+ angle = st.number_input("Angle", min_value=0.0, max_value=360.0, step=0.1)
12
+ enmo = st.number_input("ENMO", min_value=0.0, max_value=2.0, step=0.01)
 
 
 
 
13
 
14
+ if st.button("Detect Sleep State"):
15
+ input_data = np.array([[angle, enmo]])
16
+ prediction = model.predict(input_data)[0]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
+ if prediction == 0:
19
+ st.success("Sleep State: **Wakeup**")
20
  else:
21
+ st.success("Sleep State: **Onset**")