prasad6145 commited on
Commit
a10c1b5
·
verified ·
1 Parent(s): 4c7534b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import numpy as np
3
+ import tensorflow as tf
4
+
5
+ # Load the trained model
6
+ model = tf.keras.models.load_model("sleep_cognition_model")
7
+
8
+ # Define prediction function
9
+ def predict(TST, SE, WASO, REM_Sleep, Deep_Sleep, Number_of_Awakenings):
10
+ input_data = np.array([[TST, SE, WASO, REM_Sleep, Deep_Sleep, Number_of_Awakenings]])
11
+ prediction = model.predict(input_data)
12
+ return {
13
+ "Reaction Time": float(prediction[0][0]),
14
+ "Memory Recall Accuracy": float(prediction[0][1]),
15
+ "Attention Score": float(prediction[0][2]),
16
+ "Executive Function Score": float(prediction[0][3]),
17
+ "Mental Fatigue Index": float(prediction[0][4]),
18
+ }
19
+
20
+ # Define Gradio interface
21
+ iface = gr.Interface(
22
+ fn=predict,
23
+ inputs=[
24
+ gr.Number(label="Total Sleep Time (TST)"),
25
+ gr.Number(label="Sleep Efficiency (SE)"),
26
+ gr.Number(label="Wake After Sleep Onset (WASO)"),
27
+ gr.Number(label="REM Sleep (%)"),
28
+ gr.Number(label="Deep Sleep (%)"),
29
+ gr.Number(label="Number of Awakenings"),
30
+ ],
31
+ outputs="json",
32
+ title="Sleep & Cognitive Function Predictor",
33
+ description="Enter sleep parameters to predict cognitive function scores.",
34
+ )
35
+
36
+ # Run the app
37
+ iface.launch()