Fluospark128 commited on
Commit
42c8cc6
Β·
verified Β·
1 Parent(s): 6ec1cee

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -25
app.py CHANGED
@@ -6,44 +6,61 @@ import pandas as pd
6
  with open("model.pkl", "rb") as f:
7
  model = pickle.load(f)
8
 
9
- # Define prediction function
 
 
 
 
 
 
 
 
 
 
 
 
 
10
  def predict_jamb(study_hours, attendance, teacher_quality, distance,
11
  school_type, school_location, extra_tutorials, learning_materials,
12
  parent_involvement, it_knowledge, age, gender, socioeconomic_status,
13
  parent_education, assignments_completed):
14
 
15
- # Create dataframe from inputs
16
- input_data = pd.DataFrame({
17
- "Study_Hours_Per_Week": [study_hours],
18
- "Attendance_Rate": [attendance],
19
- "Teacher_Quality": [teacher_quality],
20
- "Distance_To_School": [distance],
21
- "School_Type": [school_type],
22
- "School_Location": [school_location],
23
- "Extra_Tutorials": [extra_tutorials],
24
- "Access_To_Learning_Materials": [learning_materials],
25
- "Parent_Involvement": [parent_involvement],
26
- "IT_Knowledge": [it_knowledge],
27
- "Age": [age],
28
- "Gender": [gender],
29
- "Socioeconomic_Status": [socioeconomic_status],
30
- "Parent_Education_Level": [parent_education],
31
- "Assignments_Completed": [assignments_completed]
32
- })
 
 
 
33
 
 
34
  prediction = model.predict(input_data)[0]
35
 
36
  if prediction == 0:
37
- return "Below Average"
38
  elif prediction == 1:
39
- return "Average"
40
  else:
41
- return "Pass"
42
 
43
- # Gradio interface
44
  with gr.Blocks() as demo:
45
  gr.Markdown("# πŸŽ“ JAMB Score Prediction App")
46
- gr.Markdown("Predict whether a student's JAMB score will be **Below Average**, **Average**, or **Pass**.")
47
 
48
  with gr.Row():
49
  study_hours = gr.Slider(0, 40, value=10, label="Study Hours per Week")
@@ -80,6 +97,5 @@ with gr.Blocks() as demo:
80
  outputs=output
81
  )
82
 
83
- # Launch app
84
  if __name__ == "__main__":
85
  demo.launch()
 
6
  with open("model.pkl", "rb") as f:
7
  model = pickle.load(f)
8
 
9
+ # Define categorical mappings (must match training!)
10
+ label_encoders = {
11
+ "School_Type": {"Public": 0, "Private": 1},
12
+ "School_Location": {"Urban": 0, "Rural": 1},
13
+ "Extra_Tutorials": {"No": 0, "Yes": 1},
14
+ "Access_To_Learning_Materials": {"No": 0, "Yes": 1},
15
+ "Parent_Involvement": {"Low": 0, "Medium": 1, "High": 2},
16
+ "IT_Knowledge": {"Low": 0, "Medium": 1, "High": 2},
17
+ "Gender": {"Male": 0, "Female": 1},
18
+ "Socioeconomic_Status": {"Low": 0, "Medium": 1, "High": 2},
19
+ "Parent_Education_Level": {"None": 0, "Primary": 1, "Secondary": 2, "Tertiary": 3}
20
+ }
21
+
22
+ # Prediction function
23
  def predict_jamb(study_hours, attendance, teacher_quality, distance,
24
  school_type, school_location, extra_tutorials, learning_materials,
25
  parent_involvement, it_knowledge, age, gender, socioeconomic_status,
26
  parent_education, assignments_completed):
27
 
28
+ # Encode categorical inputs
29
+ input_dict = {
30
+ "Study_Hours_Per_Week": study_hours,
31
+ "Attendance_Rate": attendance,
32
+ "Teacher_Quality": teacher_quality,
33
+ "Distance_To_School": distance,
34
+ "School_Type": label_encoders["School_Type"][school_type],
35
+ "School_Location": label_encoders["School_Location"][school_location],
36
+ "Extra_Tutorials": label_encoders["Extra_Tutorials"][extra_tutorials],
37
+ "Access_To_Learning_Materials": label_encoders["Access_To_Learning_Materials"][learning_materials],
38
+ "Parent_Involvement": label_encoders["Parent_Involvement"][parent_involvement],
39
+ "IT_Knowledge": label_encoders["IT_Knowledge"][it_knowledge],
40
+ "Age": age,
41
+ "Gender": label_encoders["Gender"][gender],
42
+ "Socioeconomic_Status": label_encoders["Socioeconomic_Status"][socioeconomic_status],
43
+ "Parent_Education_Level": label_encoders["Parent_Education_Level"][parent_education],
44
+ "Assignments_Completed": assignments_completed
45
+ }
46
+
47
+ # Convert to dataframe
48
+ input_data = pd.DataFrame([input_dict])
49
 
50
+ # Predict
51
  prediction = model.predict(input_data)[0]
52
 
53
  if prediction == 0:
54
+ return "πŸ“‰ Below Average"
55
  elif prediction == 1:
56
+ return "βš–οΈ Average"
57
  else:
58
+ return "βœ… Pass"
59
 
60
+ # Gradio UI
61
  with gr.Blocks() as demo:
62
  gr.Markdown("# πŸŽ“ JAMB Score Prediction App")
63
+ gr.Markdown("Predict student's JAMB performance (Below Average, Average, Pass).")
64
 
65
  with gr.Row():
66
  study_hours = gr.Slider(0, 40, value=10, label="Study Hours per Week")
 
97
  outputs=output
98
  )
99
 
 
100
  if __name__ == "__main__":
101
  demo.launch()