ntam0001 commited on
Commit
7640257
·
verified ·
1 Parent(s): 47b53a4

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +80 -0
app.py ADDED
@@ -0,0 +1,80 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import joblib
2
+ import gradio as gr
3
+ import numpy as np
4
+
5
+ # Load the saved Random Forest model
6
+ model = joblib.load('random_forest_model.pkl')
7
+
8
+ # Define the feature names (as per your dataset)
9
+ feature_names = [
10
+ 'Marital status', 'Application mode', 'Application order', 'Course',
11
+ 'Daytime/evening attendance', 'Previous qualification', 'Nacionality',
12
+ "Mother's qualification", "Mother's occupation", 'Displaced',
13
+ 'Educational special needs', 'Debtor', 'Tuition fees up to date',
14
+ 'Gender', 'Scholarship holder', 'Curricular units 1st sem (credited)',
15
+ 'Curricular units 1st sem (without evaluations)', 'Unemployment rate',
16
+ 'Inflation rate', 'GDP'
17
+ ]
18
+
19
+ # Define the prediction function
20
+ def predict(
21
+ marital_status, application_mode, application_order, course,
22
+ attendance, previous_qualification, nationality,
23
+ mother_qualification, mother_occupation, displaced,
24
+ special_needs, debtor, tuition_fees,
25
+ gender, scholarship_holder, curricular_units_credited,
26
+ curricular_units_without_evaluations, unemployment_rate,
27
+ inflation_rate, gdp
28
+ ):
29
+ # Create a numpy array from the input features
30
+ input_data = np.array([
31
+ marital_status, application_mode, application_order, course,
32
+ attendance, previous_qualification, nationality,
33
+ mother_qualification, mother_occupation, displaced,
34
+ special_needs, debtor, tuition_fees,
35
+ gender, scholarship_holder, curricular_units_credited,
36
+ curricular_units_without_evaluations, unemployment_rate,
37
+ inflation_rate, gdp
38
+ ]).reshape(1, -1)
39
+
40
+ # Make a prediction
41
+ prediction = model.predict(input_data)[0]
42
+
43
+ # Map the prediction to the corresponding label
44
+ if prediction == 0:
45
+ return "Dropout"
46
+ elif prediction == 1:
47
+ return "Graduate"
48
+ elif prediction == 2:
49
+ return "Enrolled"
50
+ else:
51
+ return "Unknown"
52
+
53
+ # Create a Gradio interface
54
+ inputs = [
55
+ gr.inputs.Number(label="Marital status"),
56
+ gr.inputs.Number(label="Application mode"),
57
+ gr.inputs.Number(label="Application order"),
58
+ gr.inputs.Number(label="Course"),
59
+ gr.inputs.Number(label="Daytime/evening attendance"),
60
+ gr.inputs.Number(label="Previous qualification"),
61
+ gr.inputs.Number(label="Nacionality"),
62
+ gr.inputs.Number(label="Mother's qualification"),
63
+ gr.inputs.Number(label="Mother's occupation"),
64
+ gr.inputs.Number(label="Displaced"),
65
+ gr.inputs.Number(label="Educational special needs"),
66
+ gr.inputs.Number(label="Debtor"),
67
+ gr.inputs.Number(label="Tuition fees up to date"),
68
+ gr.inputs.Number(label="Gender"),
69
+ gr.inputs.Number(label="Scholarship holder"),
70
+ gr.inputs.Number(label="Curricular units 1st sem (credited)"),
71
+ gr.inputs.Number(label="Curricular units 1st sem (without evaluations)"),
72
+ gr.inputs.Number(label="Unemployment rate"),
73
+ gr.inputs.Number(label="Inflation rate"),
74
+ gr.inputs.Number(label="GDP"),
75
+ ]
76
+
77
+ outputs = gr.outputs.Textbox(label="Prediction")
78
+
79
+ # Launch the Gradio app
80
+ gr.Interface(fn=predict, inputs=inputs, outputs=outputs, title="Student Dropout Prediction").launch()