File size: 1,953 Bytes
ba68402 df999d6 b198891 096fed5 b198891 ba68402 df999d6 ba68402 bdb85ba ba68402 bdb85ba 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 48 49 50 51 52 53 |
import gradio as gr
from tensorflow.keras.models import load_model
from tensorflow.keras.metrics import MeanAbsoluteError
import tensorflow as tf
import numpy as np
# Register custom metric
tf.keras.utils.get_custom_objects().update({"mae": MeanAbsoluteError()})
# Load your trained model
model = load_model("student_performance_model.h5")
# 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 as a NumPy array
input_data = np.array([
[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()
|