File size: 1,243 Bytes
a10c1b5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import gradio as gr
import numpy as np
import tensorflow as tf

# Load the trained model
model = tf.keras.models.load_model("sleep_cognition_model")

# Define prediction function
def predict(TST, SE, WASO, REM_Sleep, Deep_Sleep, Number_of_Awakenings):
    input_data = np.array([[TST, SE, WASO, REM_Sleep, Deep_Sleep, Number_of_Awakenings]])
    prediction = model.predict(input_data)
    return {
        "Reaction Time": float(prediction[0][0]),
        "Memory Recall Accuracy": float(prediction[0][1]),
        "Attention Score": float(prediction[0][2]),
        "Executive Function Score": float(prediction[0][3]),
        "Mental Fatigue Index": float(prediction[0][4]),
    }

# Define Gradio interface
iface = gr.Interface(
    fn=predict,
    inputs=[
        gr.Number(label="Total Sleep Time (TST)"),
        gr.Number(label="Sleep Efficiency (SE)"),
        gr.Number(label="Wake After Sleep Onset (WASO)"),
        gr.Number(label="REM Sleep (%)"),
        gr.Number(label="Deep Sleep (%)"),
        gr.Number(label="Number of Awakenings"),
    ],
    outputs="json",
    title="Sleep & Cognitive Function Predictor",
    description="Enter sleep parameters to predict cognitive function scores.",
)

# Run the app
iface.launch()