Spaces:
Runtime error
Runtime error
| 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() |