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