Simrandhiman commited on
Commit
6bf4de3
·
verified ·
1 Parent(s): bf45feb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -0
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ import joblib
4
+
5
+ # Load model & columns
6
+ model = joblib.load("student_gpa_model.pkl")
7
+ columns = joblib.load("columns.pkl")
8
+
9
+ def predict_gpa(
10
+ Age,
11
+ Gender,
12
+ Ethnicity,
13
+ ParentalEducation,
14
+ StudyTimeWeekly,
15
+ Absences,
16
+ Tutoring,
17
+ ParentalSupport,
18
+ Extracurricular,
19
+ Sports,
20
+ Music,
21
+ Volunteering
22
+ ):
23
+ data = {
24
+ "Age": Age,
25
+ "Gender": Gender,
26
+ "Ethnicity": Ethnicity,
27
+ "ParentalEducation": ParentalEducation,
28
+ "StudyTimeWeekly": StudyTimeWeekly,
29
+ "Absences": Absences,
30
+ "Tutoring": Tutoring,
31
+ "ParentalSupport": ParentalSupport,
32
+ "Extracurricular": Extracurricular,
33
+ "Sports": Sports,
34
+ "Music": Music,
35
+ "Volunteering": Volunteering,
36
+ }
37
+
38
+ df = pd.DataFrame([data])
39
+ df = pd.get_dummies(df)
40
+ df = df.reindex(columns=columns, fill_value=0)
41
+
42
+ prediction = model.predict(df)[0]
43
+ return round(float(prediction), 2)
44
+
45
+ app = gr.Interface(
46
+ fn=predict_gpa,
47
+ inputs=[
48
+ gr.Number(label="Age"),
49
+ gr.Dropdown(["Male", "Female"], label="Gender"),
50
+ gr.Dropdown(
51
+ ["Group A", "Group B", "Group C", "Group D", "Group E"],
52
+ label="Ethnicity"
53
+ ),
54
+ gr.Dropdown(
55
+ ["High School", "Associate", "Bachelor", "Master"],
56
+ label="Parental Education"
57
+ ),
58
+ gr.Number(label="Weekly Study Time (hours)"),
59
+ gr.Number(label="Absences"),
60
+ gr.Dropdown(["Yes", "No"], label="Tutoring"),
61
+ gr.Dropdown(["Low", "Medium", "High"], label="Parental Support"),
62
+ gr.Dropdown(["Yes", "No"], label="Extracurricular"),
63
+ gr.Dropdown(["Yes", "No"], label="Sports"),
64
+ gr.Dropdown(["Yes", "No"], label="Music"),
65
+ gr.Dropdown(["Yes", "No"], label="Volunteering"),
66
+ ],
67
+ outputs=gr.Number(label="Predicted GPA"),
68
+ title="Student GPA Predictor",
69
+ description="ML model to predict student GPA based on academic & lifestyle factors"
70
+ )
71
+
72
+ if __name__ == "__main__":
73
+ app.launch(server_name="0.0.0.0", server_port=7860)