nukimayasari's picture
Create app.py
ba68402 verified
raw
history blame
1.69 kB
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()