Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pickle
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
# Load model
|
| 6 |
+
with open("log_reg_model.pkl", "rb") as f:
|
| 7 |
+
model = pickle.load(f)
|
| 8 |
+
|
| 9 |
+
# Define prediction function
|
| 10 |
+
def predict_sleep(step: float, hour: float):
|
| 11 |
+
input_data = np.array([[step, hour]])
|
| 12 |
+
prediction = model.predict(input_data)[0]
|
| 13 |
+
label = "Sleep Onset" if prediction == 1 else "Wakeup"
|
| 14 |
+
return label
|
| 15 |
+
|
| 16 |
+
# Gradio interface
|
| 17 |
+
iface = gr.Interface(
|
| 18 |
+
fn=predict_sleep,
|
| 19 |
+
inputs=[
|
| 20 |
+
gr.Number(label="Step Count"),
|
| 21 |
+
gr.Number(label="Hour (0-23)")
|
| 22 |
+
],
|
| 23 |
+
outputs=gr.Text(label="Prediction"),
|
| 24 |
+
title="Sleep Prediction (Onset/Wakeup)",
|
| 25 |
+
description="Enter step count and hour to predict whether it's sleep onset or wakeup."
|
| 26 |
+
)
|
| 27 |
+
|
| 28 |
+
# Launch app
|
| 29 |
+
if __name__ == "__main__":
|
| 30 |
+
iface.launch()
|