rtnjt commited on
Commit
69302a0
·
verified ·
1 Parent(s): 389ea79

Created app.py

Browse files
Files changed (1) hide show
  1. app.py +91 -0
app.py ADDED
@@ -0,0 +1,91 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import joblib
3
+ import pandas as pd
4
+ import numpy as np
5
+ import os
6
+
7
+ # Load all trained models
8
+ models = {
9
+ "Logistic Regression": joblib.load('logistic_regression_model.pkl'),
10
+ "Random Forest": joblib.load('random_forest_model.pkl'),
11
+ "Support Vector Machine (SVM)": joblib.load('svm_model.pkl'),
12
+ "Decision Tree": joblib.load('decision_tree_model.pkl'),
13
+ "XGBoost": joblib.load('xgboost_model.pkl'),
14
+ "AdaBoost": joblib.load('adaboost_model.pkl')
15
+ }
16
+
17
+ def predict_risk(model_name, gender, age, social_category, domicile_type, first_gen,
18
+ disability_status, income_bracket, family_members, earning_members,
19
+ scholarship, loan_status, class10, class12, cgpa, backlogs, year_backs):
20
+
21
+ # Select the model based on user choice
22
+ model = models[model_name]
23
+
24
+ # Create input dataframe matching training data format
25
+ input_data = pd.DataFrame({
26
+ 'Gender': [gender],
27
+ 'Age': [age],
28
+ 'Social_Category': [social_category],
29
+ 'Domicile_Type': [domicile_type],
30
+ 'First_Gen': [first_gen],
31
+ 'Disability_Status': [disability_status],
32
+ 'Annual_Family_Income_Bracket': [income_bracket],
33
+ 'Total_Family_Members': [family_members],
34
+ 'Earning_Members': [earning_members],
35
+ 'Scholarship_Status': [scholarship],
36
+ 'Education_Loan_Status': [loan_status],
37
+ 'Class10_Percent_Bracket': [class10],
38
+ 'Class12_Percent_Bracket': [class12],
39
+ 'Current_CGPA': [cgpa],
40
+ 'Current_Backlogs': [backlogs],
41
+ 'Year_Backs': [year_backs]
42
+ })
43
+
44
+ # Make prediction
45
+ prediction = model.predict(input_data)[0]
46
+ result = "At Risk" if prediction >= 2 else "Not At Risk"
47
+
48
+ # Calculate confidence
49
+ probabilities = model.predict_proba(input_data) if hasattr(model, 'predict_proba') else None
50
+ confidence = float(np.max(probabilities)) * 100 if probabilities is not None else 85.0
51
+
52
+ return {
53
+ "model_used": model_name,
54
+ "prediction": result,
55
+ "confidence": round(confidence, 2),
56
+ "risk_score": float(prediction)
57
+ }
58
+
59
+ # Create Gradio interface
60
+ iface = gr.Interface(
61
+ fn=predict_risk,
62
+ inputs=[
63
+ gr.Dropdown(list(models.keys()), label="Select Model", value="XGBoost"),
64
+ gr.Dropdown(["Male", "Female"], label="Gender"),
65
+ gr.Number(label="Age", minimum=17, maximum=30),
66
+ gr.Dropdown(["General", "OBC", "SC", "ST", "EWS"], label="Social Category"),
67
+ gr.Dropdown(["Urban", "Semi-Urban", "Rural"], label="Domicile Type"),
68
+ gr.Dropdown(["Yes", "No"], label="First Generation"),
69
+ gr.Dropdown(["Yes", "No"], label="Disability Status"),
70
+ gr.Dropdown(["Below ₹3,00,000", "₹3,00,001 - ₹5,00,000", "₹5,00,001 - ₹8,00,000",
71
+ "₹8,00,001 - ₹12,00,000", "Above ₹12,00,000"], label="Annual Family Income"),
72
+ gr.Number(label="Total Family Members", minimum=1, maximum=15),
73
+ gr.Number(label="Earning Members", minimum=0, maximum=10),
74
+ gr.Dropdown(["Yes", "No"], label="Scholarship Status"),
75
+ gr.Dropdown(["Yes", "No"], label="Education Loan Status"),
76
+ gr.Dropdown(["Below 50%", "50% - 59.9%", "60% - 69.9%", "70% - 79.9%",
77
+ "80% - 89.9%", "90% and above"], label="Class 10 Percentage"),
78
+ gr.Dropdown(["Below 50%", "50% - 59.9%", "60% - 69.9%", "70% - 79.9%",
79
+ "80% - 89.9%", "90% and above"], label="Class 12 Percentage"),
80
+ gr.Number(label="Current CGPA", minimum=0, maximum=10, step=0.01),
81
+ gr.Number(label="Current Backlogs", minimum=0, maximum=10),
82
+ gr.Number(label="Year Backs", minimum=0, maximum=5)
83
+ ],
84
+ outputs=gr.JSON(label="Prediction Result"),
85
+ title="SETU Student At-Risk Prediction",
86
+ description="AI-powered student dropout risk assessment system with multiple ML models",
87
+ api_name="predict"
88
+ )
89
+
90
+ if __name__ == "__main__":
91
+ iface.launch()