Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import joblib
|
3 |
+
|
4 |
+
# Load your trained model
|
5 |
+
model = joblib.load("path_to_your_model.pkl")
|
6 |
+
|
7 |
+
# Define prediction function
|
8 |
+
def predict_performance(Gender, AttendanceRate, StudyHoursPerWeek, PreviousGrade, ExtracurricularActivities, ParentalSupport):
|
9 |
+
# Encoding Gender (Male/Female)
|
10 |
+
Gender_Male = 1 if Gender == 'Male' else 0
|
11 |
+
Gender_Female = 1 if Gender == 'Female' else 0
|
12 |
+
|
13 |
+
# One-hot encode ParentalSupport (Low/Medium/High)
|
14 |
+
ParentalSupport_Low = 1 if ParentalSupport == 'Low' else 0
|
15 |
+
ParentalSupport_Medium = 1 if ParentalSupport == 'Medium' else 0
|
16 |
+
ParentalSupport_High = 1 if ParentalSupport == 'High' else 0
|
17 |
+
|
18 |
+
# ExtracurricularActivities is now numeric (0-3)
|
19 |
+
# No transformation needed, it's a numeric input already
|
20 |
+
|
21 |
+
# Prepare input array
|
22 |
+
input_data = [
|
23 |
+
[Gender_Male, Gender_Female, AttendanceRate, StudyHoursPerWeek, PreviousGrade, ExtracurricularActivities,
|
24 |
+
ParentalSupport_Low, ParentalSupport_Medium, ParentalSupport_High]
|
25 |
+
]
|
26 |
+
|
27 |
+
# Predict the student's performance
|
28 |
+
prediction = model.predict(input_data)
|
29 |
+
return prediction[0]
|
30 |
+
|
31 |
+
# Gradio interface
|
32 |
+
interface = gr.Interface(
|
33 |
+
fn=predict_performance,
|
34 |
+
inputs=[
|
35 |
+
gr.Dropdown(choices=['Male', 'Female'], label='Gender'),
|
36 |
+
gr.Number(label='Attendance Rate (%)'),
|
37 |
+
gr.Number(label='Study Hours Per Week'),
|
38 |
+
gr.Number(label='Previous Grade'),
|
39 |
+
gr.Slider(0, 3, step=1, label='Number of Extracurricular Activities'), # Updated: Numeric slider (0-3)
|
40 |
+
gr.Dropdown(choices=['Low', 'Medium', 'High'], label='Parental Support')
|
41 |
+
],
|
42 |
+
outputs="text"
|
43 |
+
)
|
44 |
+
|
45 |
+
# Launch the interface
|
46 |
+
interface.launch()
|