Spaces:
Runtime error
Runtime error
File size: 3,083 Bytes
7640257 1089986 7640257 b05123e 7640257 b05123e 7640257 b05123e 7640257 |
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
import joblib
import gradio as gr
import numpy as np
# Load the saved Random Forest model
model = joblib.load('best_model.pkl')
# Define the feature names (as per your dataset)
feature_names = [
'Marital status', 'Application mode', 'Application order', 'Course',
'Daytime/evening attendance', 'Previous qualification', 'Nacionality',
"Mother's qualification", "Mother's occupation", 'Displaced',
'Educational special needs', 'Debtor', 'Tuition fees up to date',
'Gender', 'Scholarship holder', 'Curricular units 1st sem (credited)',
'Curricular units 1st sem (without evaluations)', 'Unemployment rate',
'Inflation rate', 'GDP'
]
# Define the prediction function
def predict(
marital_status, application_mode, application_order, course,
attendance, previous_qualification, nationality,
mother_qualification, mother_occupation, displaced,
special_needs, debtor, tuition_fees,
gender, scholarship_holder, curricular_units_credited,
curricular_units_without_evaluations, unemployment_rate,
inflation_rate, gdp
):
# Create a numpy array from the input features
input_data = np.array([
marital_status, application_mode, application_order, course,
attendance, previous_qualification, nationality,
mother_qualification, mother_occupation, displaced,
special_needs, debtor, tuition_fees,
gender, scholarship_holder, curricular_units_credited,
curricular_units_without_evaluations, unemployment_rate,
inflation_rate, gdp
]).reshape(1, -1)
# Make a prediction
prediction = model.predict(input_data)[0]
# Map the prediction to the corresponding label
if prediction == 0:
return "Dropout"
elif prediction == 1:
return "Graduate"
elif prediction == 2:
return "Enrolled"
else:
return "Unknown"
# Create a Gradio interface
inputs = [
gr.inputs.Number(label="Marital status"),
gr.inputs.Number(label="Application mode"),
gr.inputs.Number(label="Application order"),
gr.inputs.Number(label="Course"),
gr.inputs.Number(label="Daytime/evening attendance"),
gr.inputs.Number(label="Previous qualification"),
gr.inputs.Number(label="Nacionality"),
gr.inputs.Number(label="Mother's qualification"),
gr.inputs.Number(label="Mother's occupation"),
gr.inputs.Number(label="Displaced"),
gr.inputs.Number(label="Educational special needs"),
gr.inputs.Number(label="Debtor"),
gr.inputs.Number(label="Tuition fees up to date"),
gr.inputs.Number(label="Gender"),
gr.inputs.Number(label="Scholarship holder"),
gr.inputs.Number(label="Curricular units 1st sem (credited)"),
gr.inputs.Number(label="Curricular units 1st sem (without evaluations)"),
gr.inputs.Number(label="Unemployment rate"),
gr.inputs.Number(label="Inflation rate"),
gr.inputs.Number(label="GDP"),
]
outputs = gr.outputs.Textbox(label="Prediction")
# Launch the Gradio app
gr.Interface(fn=predict, inputs=inputs, outputs=outputs, title="Student Dropout Prediction").launch() |