Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,20 +1,37 @@
|
|
1 |
import streamlit as st
|
|
|
2 |
import joblib
|
3 |
-
import numpy as np
|
4 |
|
5 |
-
# Load
|
6 |
-
model = joblib.load("log_reg_model.pkl") # or
|
7 |
|
8 |
-
|
9 |
-
st.title("AI Sleep State Detector")
|
10 |
-
st.write("Predict sleep state (`onset` or `wakeup`) using step count and hour.")
|
11 |
|
12 |
-
#
|
13 |
-
|
14 |
-
|
|
|
|
|
|
|
15 |
|
16 |
-
#
|
17 |
-
if
|
18 |
-
|
19 |
-
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.")
|