Fluospark128 commited on
Commit
b09a08c
Β·
verified Β·
1 Parent(s): a9c33df

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -0
app.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pickle
3
+ import pandas as pd
4
+
5
+ # Load model
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")
50
+ attendance = gr.Slider(0, 100, value=80, label="Attendance Rate (%)")
51
+ teacher_quality = gr.Dropdown([1,2,3,4,5], label="Teacher Quality")
52
+ distance = gr.Number(value=5, label="Distance to School (km)")
53
+
54
+ with gr.Row():
55
+ school_type = gr.Radio(["Public", "Private"], label="School Type")
56
+ school_location = gr.Radio(["Urban", "Rural"], label="School Location")
57
+ extra_tutorials = gr.Radio(["Yes", "No"], label="Extra Tutorials")
58
+ learning_materials = gr.Radio(["Yes", "No"], label="Access to Learning Materials")
59
+
60
+ with gr.Row():
61
+ parent_involvement = gr.Dropdown(["Low", "Medium", "High"], label="Parent Involvement")
62
+ it_knowledge = gr.Dropdown(["Low", "Medium", "High"], label="IT Knowledge")
63
+ age = gr.Slider(10, 30, value=18, label="Age")
64
+ gender = gr.Radio(["Male", "Female"], label="Gender")
65
+
66
+ with gr.Row():
67
+ socioeconomic_status = gr.Dropdown(["Low", "Medium", "High"], label="Socioeconomic Status")
68
+ parent_education = gr.Dropdown(["None", "Primary", "Secondary", "Tertiary"], label="Parent Education")
69
+ assignments_completed = gr.Slider(0, 10, value=2, label="Assignments Completed")
70
+
71
+ output = gr.Textbox(label="Prediction")
72
+
73
+ submit_btn = gr.Button("Predict")
74
+ submit_btn.click(
75
+ predict_jamb,
76
+ inputs=[study_hours, attendance, teacher_quality, distance,
77
+ school_type, school_location, extra_tutorials, learning_materials,
78
+ parent_involvement, it_knowledge, age, gender, socioeconomic_status,
79
+ parent_education, assignments_completed],
80
+ outputs=output
81
+ )
82
+
83
+ # Launch app
84
+ if __name__ == "__main__":
85
+ demo.launch()