Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,104 +1,104 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import numpy as np
|
| 3 |
-
import joblib
|
| 4 |
-
|
| 5 |
-
# Load model
|
| 6 |
-
model = joblib.load("
|
| 7 |
-
|
| 8 |
-
# Setup page
|
| 9 |
-
st.set_page_config(page_title="Dự đoán tốt nghiệp đúng hạn", page_icon="🎓", layout="wide")
|
| 10 |
-
|
| 11 |
-
# Inject custom CSS
|
| 12 |
-
st.markdown("""
|
| 13 |
-
<style>
|
| 14 |
-
html, body, [class*="css"] {
|
| 15 |
-
font-family: 'Poppins', sans-serif;
|
| 16 |
-
}
|
| 17 |
-
.block-container {
|
| 18 |
-
padding: 2rem 2rem 2rem 2rem;
|
| 19 |
-
}
|
| 20 |
-
.stButton button {
|
| 21 |
-
background: linear-gradient(90deg, #4F8BF9 0%, #8E2DE2 100%);
|
| 22 |
-
border: none;
|
| 23 |
-
padding: 0.75em 1.5em;
|
| 24 |
-
border-radius: 8px;
|
| 25 |
-
color: white;
|
| 26 |
-
font-size: 18px;
|
| 27 |
-
font-weight: bold;
|
| 28 |
-
}
|
| 29 |
-
</style>
|
| 30 |
-
""", unsafe_allow_html=True)
|
| 31 |
-
|
| 32 |
-
# ===== HEADER =====
|
| 33 |
-
st.markdown("<h1 style='text-align: center; color: #003366;'>🎓 DỰ BÁO KHẢ NĂNG TỐT NGHIỆP ĐÚNG HẠN</h1>", unsafe_allow_html=True)
|
| 34 |
-
st.markdown("<h4 style='text-align: center; color: #666;'>Áp dụng cho sinh viên năm 3</h4>", unsafe_allow_html=True)
|
| 35 |
-
st.write("---")
|
| 36 |
-
|
| 37 |
-
# ===== Thông tin cá nhân =====
|
| 38 |
-
with st.container():
|
| 39 |
-
col1, col2, col3 = st.columns(3)
|
| 40 |
-
with col1:
|
| 41 |
-
name = st.text_input("👤 Họ và tên")
|
| 42 |
-
with col2:
|
| 43 |
-
student_id = st.text_input("🎓 Mã sinh viên")
|
| 44 |
-
with col3:
|
| 45 |
-
major = st.selectbox("📚 Ngành học", ["0 - Công nghệ thông tin", "1 - Kinh tế"])
|
| 46 |
-
|
| 47 |
-
st.write("---")
|
| 48 |
-
|
| 49 |
-
# ===== Input Semester Info =====
|
| 50 |
-
def input_semester(semester_label):
|
| 51 |
-
with st.expander(f"📖 {semester_label}", expanded=True):
|
| 52 |
-
col1, col2 = st.columns(2)
|
| 53 |
-
|
| 54 |
-
with col1:
|
| 55 |
-
somon0thi = st.number_input("Số môn không thi", min_value=0, value=0, key=f"somon0thi_{semester_label}")
|
| 56 |
-
sotc0thi = st.number_input("Số tín chỉ không thi", min_value=0, value=0, key=f"sotc0thi_{semester_label}")
|
| 57 |
-
sotcno = st.number_input("Số tín chỉ nợ", min_value=0, value=0, key=f"sotcno_{semester_label}")
|
| 58 |
-
mhno = st.number_input("Số môn không đạt", min_value=0, value=0, key=f"mhno_{semester_label}")
|
| 59 |
-
|
| 60 |
-
with col2:
|
| 61 |
-
TCHK = st.number_input("Tổng số tín chỉ", min_value=0, value=0, key=f"TCHK_{semester_label}")
|
| 62 |
-
smhk = st.number_input("Tổng số môn học kỳ", min_value=0, value=0, key=f"smhk_{semester_label}")
|
| 63 |
-
mhpass = st.number_input("Số môn đạt", min_value=0, value=0, key=f"mhpass_{semester_label}")
|
| 64 |
-
TBCHK = st.number_input("GPA", min_value=0.0, max_value=10.0, value=0.0, step=0.01, key=f"TBCHK_{semester_label}")
|
| 65 |
-
|
| 66 |
-
xep_loai_option = {
|
| 67 |
-
'0 - Giỏi': 0,
|
| 68 |
-
'1 - Khá': 1,
|
| 69 |
-
'2 - TB Khá': 2,
|
| 70 |
-
'3 - Kém': 3,
|
| 71 |
-
'4 - Xuất sắc': 4,
|
| 72 |
-
'5 - Trung Bình': 5,
|
| 73 |
-
'6 - Yếu': 6
|
| 74 |
-
}
|
| 75 |
-
xep_loai_selected = st.selectbox("Xếp loại", list(xep_loai_option.keys()), key=f"xep_loai_{semester_label}")
|
| 76 |
-
xep_loai_value = xep_loai_option[xep_loai_selected]
|
| 77 |
-
|
| 78 |
-
return [somon0thi, sotc0thi, sotcno, mhno, TCHK, smhk, mhpass, TBCHK, xep_loai_value]
|
| 79 |
-
|
| 80 |
-
# ===== Collect Data =====
|
| 81 |
-
data = []
|
| 82 |
-
semesters = ["HỌC KỲ I", "HỌC KỲ II", "HỌC KỲ III", "HỌC KỲ IV", "HỌC KỲ V", "HỌC KỲ VI"]
|
| 83 |
-
for sem in semesters:
|
| 84 |
-
data += input_semester(sem)
|
| 85 |
-
|
| 86 |
-
# ===== Prepare Data for Prediction =====
|
| 87 |
-
nganh = 0 if major.startswith("0") else 1
|
| 88 |
-
final_features = np.array(data + [nganh]).reshape(1, -1)
|
| 89 |
-
|
| 90 |
-
# ===== Predict Button =====
|
| 91 |
-
st.write("")
|
| 92 |
-
if st.button("🎯 DỰ BÁO"):
|
| 93 |
-
prediction = model.predict(final_features)
|
| 94 |
-
|
| 95 |
-
if prediction[0] == 1:
|
| 96 |
-
st.success(f"🎉 Chúc mừng bạn {name} - {major.split('-')[1].strip()}! Bạn có khả năng tốt nghiệp đúng hạn!")
|
| 97 |
-
st.balloons()
|
| 98 |
-
else:
|
| 99 |
-
st.error(f"⚠️ Bạn {name} - {major.split('-')[1].strip()} cần cố gắng hơn! Có nguy cơ trễ hạn.")
|
| 100 |
-
st.snow()
|
| 101 |
-
|
| 102 |
-
# ===== Footer =====
|
| 103 |
-
st.write("---")
|
| 104 |
-
st.caption("Developed by Quán Trà AI | 2025")
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import numpy as np
|
| 3 |
+
import joblib
|
| 4 |
+
|
| 5 |
+
# Load model
|
| 6 |
+
model = joblib.load("GradOnTime/TomekLinks_rf_model.pkl")
|
| 7 |
+
|
| 8 |
+
# Setup page
|
| 9 |
+
st.set_page_config(page_title="Dự đoán tốt nghiệp đúng hạn", page_icon="🎓", layout="wide")
|
| 10 |
+
|
| 11 |
+
# Inject custom CSS
|
| 12 |
+
st.markdown("""
|
| 13 |
+
<style>
|
| 14 |
+
html, body, [class*="css"] {
|
| 15 |
+
font-family: 'Poppins', sans-serif;
|
| 16 |
+
}
|
| 17 |
+
.block-container {
|
| 18 |
+
padding: 2rem 2rem 2rem 2rem;
|
| 19 |
+
}
|
| 20 |
+
.stButton button {
|
| 21 |
+
background: linear-gradient(90deg, #4F8BF9 0%, #8E2DE2 100%);
|
| 22 |
+
border: none;
|
| 23 |
+
padding: 0.75em 1.5em;
|
| 24 |
+
border-radius: 8px;
|
| 25 |
+
color: white;
|
| 26 |
+
font-size: 18px;
|
| 27 |
+
font-weight: bold;
|
| 28 |
+
}
|
| 29 |
+
</style>
|
| 30 |
+
""", unsafe_allow_html=True)
|
| 31 |
+
|
| 32 |
+
# ===== HEADER =====
|
| 33 |
+
st.markdown("<h1 style='text-align: center; color: #003366;'>🎓 DỰ BÁO KHẢ NĂNG TỐT NGHIỆP ĐÚNG HẠN</h1>", unsafe_allow_html=True)
|
| 34 |
+
st.markdown("<h4 style='text-align: center; color: #666;'>Áp dụng cho sinh viên năm 3</h4>", unsafe_allow_html=True)
|
| 35 |
+
st.write("---")
|
| 36 |
+
|
| 37 |
+
# ===== Thông tin cá nhân =====
|
| 38 |
+
with st.container():
|
| 39 |
+
col1, col2, col3 = st.columns(3)
|
| 40 |
+
with col1:
|
| 41 |
+
name = st.text_input("👤 Họ và tên")
|
| 42 |
+
with col2:
|
| 43 |
+
student_id = st.text_input("🎓 Mã sinh viên")
|
| 44 |
+
with col3:
|
| 45 |
+
major = st.selectbox("📚 Ngành học", ["0 - Công nghệ thông tin", "1 - Kinh tế"])
|
| 46 |
+
|
| 47 |
+
st.write("---")
|
| 48 |
+
|
| 49 |
+
# ===== Input Semester Info =====
|
| 50 |
+
def input_semester(semester_label):
|
| 51 |
+
with st.expander(f"📖 {semester_label}", expanded=True):
|
| 52 |
+
col1, col2 = st.columns(2)
|
| 53 |
+
|
| 54 |
+
with col1:
|
| 55 |
+
somon0thi = st.number_input("Số môn không thi", min_value=0, value=0, key=f"somon0thi_{semester_label}")
|
| 56 |
+
sotc0thi = st.number_input("Số tín chỉ không thi", min_value=0, value=0, key=f"sotc0thi_{semester_label}")
|
| 57 |
+
sotcno = st.number_input("Số tín chỉ nợ", min_value=0, value=0, key=f"sotcno_{semester_label}")
|
| 58 |
+
mhno = st.number_input("Số môn không đạt", min_value=0, value=0, key=f"mhno_{semester_label}")
|
| 59 |
+
|
| 60 |
+
with col2:
|
| 61 |
+
TCHK = st.number_input("Tổng số tín chỉ", min_value=0, value=0, key=f"TCHK_{semester_label}")
|
| 62 |
+
smhk = st.number_input("Tổng số môn học kỳ", min_value=0, value=0, key=f"smhk_{semester_label}")
|
| 63 |
+
mhpass = st.number_input("Số môn đạt", min_value=0, value=0, key=f"mhpass_{semester_label}")
|
| 64 |
+
TBCHK = st.number_input("GPA", min_value=0.0, max_value=10.0, value=0.0, step=0.01, key=f"TBCHK_{semester_label}")
|
| 65 |
+
|
| 66 |
+
xep_loai_option = {
|
| 67 |
+
'0 - Giỏi': 0,
|
| 68 |
+
'1 - Khá': 1,
|
| 69 |
+
'2 - TB Khá': 2,
|
| 70 |
+
'3 - Kém': 3,
|
| 71 |
+
'4 - Xuất sắc': 4,
|
| 72 |
+
'5 - Trung Bình': 5,
|
| 73 |
+
'6 - Yếu': 6
|
| 74 |
+
}
|
| 75 |
+
xep_loai_selected = st.selectbox("Xếp loại", list(xep_loai_option.keys()), key=f"xep_loai_{semester_label}")
|
| 76 |
+
xep_loai_value = xep_loai_option[xep_loai_selected]
|
| 77 |
+
|
| 78 |
+
return [somon0thi, sotc0thi, sotcno, mhno, TCHK, smhk, mhpass, TBCHK, xep_loai_value]
|
| 79 |
+
|
| 80 |
+
# ===== Collect Data =====
|
| 81 |
+
data = []
|
| 82 |
+
semesters = ["HỌC KỲ I", "HỌC KỲ II", "HỌC KỲ III", "HỌC KỲ IV", "HỌC KỲ V", "HỌC KỲ VI"]
|
| 83 |
+
for sem in semesters:
|
| 84 |
+
data += input_semester(sem)
|
| 85 |
+
|
| 86 |
+
# ===== Prepare Data for Prediction =====
|
| 87 |
+
nganh = 0 if major.startswith("0") else 1
|
| 88 |
+
final_features = np.array(data + [nganh]).reshape(1, -1)
|
| 89 |
+
|
| 90 |
+
# ===== Predict Button =====
|
| 91 |
+
st.write("")
|
| 92 |
+
if st.button("🎯 DỰ BÁO"):
|
| 93 |
+
prediction = model.predict(final_features)
|
| 94 |
+
|
| 95 |
+
if prediction[0] == 1:
|
| 96 |
+
st.success(f"🎉 Chúc mừng bạn {name} - {major.split('-')[1].strip()}! Bạn có khả năng tốt nghiệp đúng hạn!")
|
| 97 |
+
st.balloons()
|
| 98 |
+
else:
|
| 99 |
+
st.error(f"⚠️ Bạn {name} - {major.split('-')[1].strip()} cần cố gắng hơn! Có nguy cơ trễ hạn.")
|
| 100 |
+
st.snow()
|
| 101 |
+
|
| 102 |
+
# ===== Footer =====
|
| 103 |
+
st.write("---")
|
| 104 |
+
st.caption("Developed by Quán Trà AI | 2025")
|