Spaces:
Runtime error
Runtime error
Delete app.py
Browse files
app.py
DELETED
@@ -1,47 +0,0 @@
|
|
1 |
-
import os
|
2 |
-
os.environ["CUDA_VISIBLE_DEVICES"] = "-1" # Disable GPU and force CPU mode
|
3 |
-
|
4 |
-
import gradio as gr
|
5 |
-
import numpy as np
|
6 |
-
import tensorflow as tf
|
7 |
-
|
8 |
-
model_path = "sleep_cognition_model.h5"
|
9 |
-
|
10 |
-
# Check if the model file exists before loading
|
11 |
-
if not os.path.exists(model_path):
|
12 |
-
raise FileNotFoundError(f"⚠️ Model file not found: {model_path}. Please upload it to Hugging Face Space.")
|
13 |
-
|
14 |
-
|
15 |
-
# Load the trained model
|
16 |
-
model = tf.keras.models.load_model("sleep_cognition_model.h5")
|
17 |
-
|
18 |
-
# Define prediction function
|
19 |
-
def predict(TST, SE, WASO, REM_Sleep, Deep_Sleep, Number_of_Awakenings):
|
20 |
-
input_data = np.array([[TST, SE, WASO, REM_Sleep, Deep_Sleep, Number_of_Awakenings]])
|
21 |
-
prediction = model.predict(input_data)
|
22 |
-
return {
|
23 |
-
"Reaction Time": float(prediction[0][0]),
|
24 |
-
"Memory Recall Accuracy": float(prediction[0][1]),
|
25 |
-
"Attention Score": float(prediction[0][2]),
|
26 |
-
"Executive Function Score": float(prediction[0][3]),
|
27 |
-
"Mental Fatigue Index": float(prediction[0][4]),
|
28 |
-
}
|
29 |
-
|
30 |
-
# Define Gradio interface
|
31 |
-
iface = gr.Interface(
|
32 |
-
fn=predict,
|
33 |
-
inputs=[
|
34 |
-
gr.Number(label="Total Sleep Time (TST)"),
|
35 |
-
gr.Number(label="Sleep Efficiency (SE)"),
|
36 |
-
gr.Number(label="Wake After Sleep Onset (WASO)"),
|
37 |
-
gr.Number(label="REM Sleep (%)"),
|
38 |
-
gr.Number(label="Deep Sleep (%)"),
|
39 |
-
gr.Number(label="Number of Awakenings"),
|
40 |
-
],
|
41 |
-
outputs="json",
|
42 |
-
title="Sleep & Cognitive Function Predictor",
|
43 |
-
description="Enter sleep parameters to predict cognitive function scores.",
|
44 |
-
)
|
45 |
-
|
46 |
-
# Run the app
|
47 |
-
iface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|