Download app.py from rtnjt/SETU_ERP: direct link, hf CLI and curl.
- Browser
- Download file 3.96 kB
-
https://huggingface.co/spaces/rtnjt/SETU_ERP/resolve/main/app.py
- Command line
-
hf download hf://spaces/rtnjt/SETU_ERP/app.py
-
curl -L -o app.py https://huggingface.co/spaces/rtnjt/SETU_ERP/resolve/main/app.py
3.96 kB
| import gradio as gr | |
| import joblib | |
| import pandas as pd | |
| import numpy as np | |
| import os | |
| # Load all trained models | |
| models = { | |
| "Logistic Regression": joblib.load('logistic_regression_model.pkl'), | |
| "Random Forest": joblib.load('random_forest_model.pkl'), | |
| "Support Vector Machine (SVM)": joblib.load('svm_model.pkl'), | |
| "Decision Tree": joblib.load('decision_tree_model.pkl'), | |
| "XGBoost": joblib.load('xgboost_model.pkl'), | |
| "AdaBoost": joblib.load('adaboost_model.pkl') | |
| } | |
| def predict_risk(model_name, gender, age, social_category, domicile_type, first_gen, | |
| disability_status, income_bracket, family_members, earning_members, | |
| scholarship, loan_status, class10, class12, cgpa, backlogs, year_backs): | |
| # Select the model based on user choice | |
| model = models[model_name] | |
| # Create input dataframe matching training data format | |
| input_data = pd.DataFrame({ | |
| 'Gender': [gender], | |
| 'Age': [age], | |
| 'Social_Category': [social_category], | |
| 'Domicile_Type': [domicile_type], | |
| 'First_Gen': [first_gen], | |
| 'Disability_Status': [disability_status], | |
| 'Annual_Family_Income_Bracket': [income_bracket], | |
| 'Total_Family_Members': [family_members], | |
| 'Earning_Members': [earning_members], | |
| 'Scholarship_Status': [scholarship], | |
| 'Education_Loan_Status': [loan_status], | |
| 'Class10_Percent_Bracket': [class10], | |
| 'Class12_Percent_Bracket': [class12], | |
| 'Current_CGPA': [cgpa], | |
| 'Current_Backlogs': [backlogs], | |
| 'Year_Backs': [year_backs] | |
| }) | |
| # Make prediction | |
| prediction = model.predict(input_data)[0] | |
| result = "At Risk" if prediction >= 2 else "Not At Risk" | |
| # Calculate confidence | |
| probabilities = model.predict_proba(input_data) if hasattr(model, 'predict_proba') else None | |
| confidence = float(np.max(probabilities)) * 100 if probabilities is not None else 85.0 | |
| return { | |
| "model_used": model_name, | |
| "prediction": result, | |
| "confidence": round(confidence, 2), | |
| "risk_score": float(prediction) | |
| } | |
| # Create Gradio interface | |
| iface = gr.Interface( | |
| fn=predict_risk, | |
| inputs=[ | |
| gr.Dropdown(list(models.keys()), label="Select Model", value="XGBoost"), | |
| gr.Dropdown(["Male", "Female"], label="Gender"), | |
| gr.Number(label="Age", minimum=17, maximum=30), | |
| gr.Dropdown(["General", "OBC", "SC", "ST", "EWS"], label="Social Category"), | |
| gr.Dropdown(["Urban", "Semi-Urban", "Rural"], label="Domicile Type"), | |
| gr.Dropdown(["Yes", "No"], label="First Generation"), | |
| gr.Dropdown(["Yes", "No"], label="Disability Status"), | |
| gr.Dropdown(["Below ₹3,00,000", "₹3,00,001 - ₹5,00,000", "₹5,00,001 - ₹8,00,000", | |
| "₹8,00,001 - ₹12,00,000", "Above ₹12,00,000"], label="Annual Family Income"), | |
| gr.Number(label="Total Family Members", minimum=1, maximum=15), | |
| gr.Number(label="Earning Members", minimum=0, maximum=10), | |
| gr.Dropdown(["Yes", "No"], label="Scholarship Status"), | |
| gr.Dropdown(["Yes", "No"], label="Education Loan Status"), | |
| gr.Dropdown(["Below 50%", "50% - 59.9%", "60% - 69.9%", "70% - 79.9%", | |
| "80% - 89.9%", "90% and above"], label="Class 10 Percentage"), | |
| gr.Dropdown(["Below 50%", "50% - 59.9%", "60% - 69.9%", "70% - 79.9%", | |
| "80% - 89.9%", "90% and above"], label="Class 12 Percentage"), | |
| gr.Number(label="Current CGPA", minimum=0, maximum=10, step=0.01), | |
| gr.Number(label="Current Backlogs", minimum=0, maximum=10), | |
| gr.Number(label="Year Backs", minimum=0, maximum=5) | |
| ], | |
| outputs=gr.JSON(label="Prediction Result"), | |
| title="SETU Student At-Risk Prediction", | |
| description="AI-powered student dropout risk assessment system with multiple ML models", | |
| api_name="predict" | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() | |