24GE3152
PROBLEM SOLVING
AND
PYTHON
PROGRAMING
PYTHON SEMINOR
[Link]
25RUADB035
App: GuardianAI: WATCH. DETECT.
PROTECT
•GuardianAI is a smart
student monitoring system.
•Uses Artificial Intelligence
to predict student dropouts.
•Provides early alerts for
mentors and institutions.
•Goal: Zero Dropouts,
Infinite Potential.
Full code of this
application
[Link]
Guardian ai App [Link]
WEB APP
🧩 Importing Required Libraries
Code: ◦ Explanation:
•streamlit → Used to create a web-
◦ import streamlit as st
based user interface.
◦ import pandas as pd •pandas, numpy → Handle data and
◦ import numpy as np perform numerical operations.
◦ from model import train_and_evaluate, •model module → Contains ML model
save_model, load_model, predict_df functions like training, saving,
◦ from generate_sample_data import loading, and predicting.
generate •generate_sample_data → Generates
◦ import [Link] as px synthetic data for testing.
•[Link] → For interactive
◦ import os
charts and data visualization.
◦ from dotenv import load_dotenv
•os, dotenv → Manage file paths and
◦ import smtplib environment variables.
◦ from [Link] import •smtplib, EmailMessage → Send
EmailMessage automated emails through SMTP.
🧠 Page Configuration
CODE:
load_dotenv()
st.set_page_config(page_title="𝙂𝙪𝙖𝙧 𝙙𝙞 𝙖𝙣𝘼𝙄 ",
layout="wide")
Explanation:
• load_dotenv() loads sensitive data (like email
credentials) from .env.
• st.set_page_config() customizes the app title
and layout (wide screen).
Banner Section
CODE:
banner_path = "[Link]"
if [Link](banner_path):
from PIL import Image
banner_img = [Link](banner_path)
[Link](banner_img, use_container_width=True)
else:
[Link]("Banner image not found. Please check
the path!")
Explanation:
• Displays a banner image on top of the Streamlit
page.
• If the image file is missing, a warning message
🧾 App Title & Subtitle
"
align: center; color: #2E86C1; font-size: 48px;'>
ᴛᴄʜ. ᴅᴇᴛᴇᴄᴛ. ᴘʀᴏᴛᴇᴄᴛ
lign: center; color: #555; font-size: 20px;'>Zero Dropouts, Infinite Pote
w_html=True)
styled title and tagline in the center of the page using HTML formatting
🧭 Sidebar – User Options
Code:
[Link]("## 📊 Data / Model Selection")
data_option = [Link]("Choose data", ("Use sample data", "Upload
Single CSV", "Upload multiple CSVs (Attendance, Tests, Fees)"))
model_option = [Link]("Model action", ("Train new model", "Load
existing model (dropout_model.joblib)"))
tion:
r allows users to choose between:
generated sample data, or uploading CSV files.
g a new model or loading an already trained one.
📂 Data Loading & Handling
Code:
if data_option == "Use sample data":
df = generate(2000)
elif data_option == "Upload Single CSV":
uploaded_file = [Link].file_uploader("Upload students CSV", type=["csv"])
if uploaded_file:
df = pd.read_csv(uploaded_file)
elif data_option == "Upload multiple CSVs (Attendance, Tests, Fees)":
att_file = [Link].file_uploader("Upload Attendance CSV", type=["csv"],
key="att")
test_file = [Link].file_uploader("Upload Tests CSV", type=["csv"], key="test")
fee_file = [Link].file_uploader("Upload Fees CSV", type=["csv"], key="fee")
Explanation:
Users can either:
• Generate random sample data (2000 students).
• Upload one complete student CSV.
• Upload three separate CSVs for attendance, test scores, and fees.
🔍 Data Validation
Code:
required_cols =
["student_id","gender","scholarship","attendance_pct","avg_assignment_pct",
"avg_test_pct","fee_delay_days","num_attempts","prior_arrears","engagement
_score","dropout_risk"]
missing = [c for c in required_cols if c not in [Link]]
if missing:
[Link](f"Missing columns: {missing}. Using sample data may fill all
required columns.")
Explanation:
• Checks whether all the required columns exist in the uploaded dataset.
• If any are missing, a warning message is displayed.
📊Display Dataset
Code:
[Link]("### STUDENTS DATASET (up to 1000
rows)")
[Link]([Link](1000))
Explanation:
• Displays the top 1000 rows of the dataset as an
interactive table inside the Streamlit app
🧮 Model Training or Loading
_option == "Train new model":
utton("Train model on selected dataset"):
del, metrics = train_and_evaluate(df)
e_model(model, "dropout_model.joblib")
= load_model("dropout_model.joblib")
ion:
n new model” is selected, the app trains a new ML model and saves it.
wise, it loads an existing model (dropout_model.joblib).
🧠Prediction Section
Code:
predict_option = [Link]("Prediction source", ("Predict on
dataset shown above", "Upload new students to predict"))
pred_df = predict_df(model, df)
Explanation:
• The model predicts dropout probabilities either for the shown
dataset or for new uploaded student data.
⚠️ Risk Level Classification
Code:
def assign_risk_level(p):
if p < 0.3: return "Low"
elif p < 0.6: return "Medium"
else: return "High"
pred_df["risk_level"] =
pred_df["risk_proba"].apply(assign_risk_level)
Explanation:
Converts dropout probability into risk categories:
• Low Risk: Below 0.3
• Medium Risk: Between 0.3 and 0.6
• High Risk: Above 0.6
📉 Visualization
Code:
fig = [Link](pred_df, x="risk_proba",
nbins=30, color="risk_level")
st.plotly_chart(fig)
pie_fig = [Link](pred_df, names="risk_level")
st.plotly_chart(pie_fig)
Explanation:
Histogram → Risk probability distribution
Pie chart → Risk category percentage
🧾 High-Risk Table &
Download
Code:
high_risk = pred_df[pred_df["risk_proba"] >=
threshold]
st.download_button("📥 Download High-risk CSV",
high_risk.to_csv(index=False))
Explanation:
• Filters students with high dropout risk (above
the selected threshold).
💌 Email Notification System
Code:
def send_email(to_email, subject, body):
host = [Link]("EMAIL_HOST")
...
with [Link](max_workers=5)
as executor:
futures = [[Link](send_email, e[0], e[1], e[2]) for e
in email_tasks]
Explanation:
• Automatically sends personalized emails to high-risk
students for counseling.
• Uses SMTP credentials stored in .env.
• Multi-threading (ThreadPoolExecutor) allows sending
multiple emails simultaneously.
🎥YouTube Tutorial Section
Code:
[Link]("""
<iframe width="640" height="360"
src="[Link]
TfBiKo"></iframe>
""", unsafe_allow_html=True)
Explanation:
Embeds a YouTube video tutorial directly inside the app for
guidance.
🧾 Footer Section
Code:
[Link]("""
<div class="footer">
© 2025 GuardianAI | Developed by
<b>GEN Z CODERS</b>
</div>
""", unsafe_allow_html=True)
Explanation:
Adds a footer with project credits and
contact information