Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import pickle, os
|
| 4 |
+
|
| 5 |
+
MODEL_PATH = "student_model.pkl"
|
| 6 |
+
|
| 7 |
+
def load_model():
|
| 8 |
+
if not os.path.exists(MODEL_PATH):
|
| 9 |
+
raise FileNotFoundError("student_model.pkl not found. Upload or run train.py first.")
|
| 10 |
+
with open(MODEL_PATH, "rb") as f:
|
| 11 |
+
bundle = pickle.load(f)
|
| 12 |
+
return bundle["model"], bundle["features"], bundle["targets"]
|
| 13 |
+
|
| 14 |
+
model, FEATURE_COLS, TARGET_COLS = load_model()
|
| 15 |
+
|
| 16 |
+
def predict_fn(attendance, study_hours, parent_support, sleep_hours, reading_hours, behavior_score, pretest_score, homework_completion, participation):
|
| 17 |
+
row = pd.DataFrame([{
|
| 18 |
+
"Attendance": attendance,
|
| 19 |
+
"StudyHours": study_hours,
|
| 20 |
+
"ParentalSupport": parent_support,
|
| 21 |
+
"SleepHours": sleep_hours,
|
| 22 |
+
"ReadingHours": reading_hours,
|
| 23 |
+
"BehaviorScore": behavior_score,
|
| 24 |
+
"PretestScore": pretest_score,
|
| 25 |
+
"HomeworkCompletion": homework_completion,
|
| 26 |
+
"Participation": participation
|
| 27 |
+
}])
|
| 28 |
+
y_pred = model.predict(row)[0]
|
| 29 |
+
return {TARGET_COLS[0]: float(y_pred[0]), TARGET_COLS[1]: float(y_pred[1])}
|
| 30 |
+
|
| 31 |
+
with gr.Blocks() as iface:
|
| 32 |
+
gr.Markdown("# Student Score Predictor (Pickle Model)")
|
| 33 |
+
with gr.Row():
|
| 34 |
+
attendance = gr.Slider(0, 100, value=90, step=1, label="Attendance (%)")
|
| 35 |
+
study_hours = gr.Slider(0, 20, value=5, step=1, label="Study Hours / week")
|
| 36 |
+
parent_support = gr.Slider(1, 5, value=3, step=1, label="Parental Support (1-5)")
|
| 37 |
+
with gr.Row():
|
| 38 |
+
sleep_hours = gr.Slider(0, 12, value=8, step=1, label="Sleep Hours / night")
|
| 39 |
+
reading_hours = gr.Slider(0, 20, value=2, step=1, label="Reading Hours / week")
|
| 40 |
+
behavior_score = gr.Slider(1, 10, value=7, step=1, label="Behavior Score (1-10)")
|
| 41 |
+
with gr.Row():
|
| 42 |
+
pretest_score = gr.Slider(0, 100, value=70, step=1, label="Pretest Score")
|
| 43 |
+
homework_completion = gr.Slider(0, 100, value=85, step=1, label="Homework Completion (%)")
|
| 44 |
+
participation = gr.Slider(1, 10, value=6, step=1, label="Participation (1-10)")
|
| 45 |
+
|
| 46 |
+
out = gr.JSON(label="Predicted Scores")
|
| 47 |
+
gr.Button("Predict").click(
|
| 48 |
+
predict_fn,
|
| 49 |
+
[attendance, study_hours, parent_support, sleep_hours, reading_hours, behavior_score, pretest_score, homework_completion, participation],
|
| 50 |
+
out
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
if __name__ == "__main__":
|
| 54 |
+
iface.launch()
|