namngo commited on
Commit
3a15f23
·
verified ·
1 Parent(s): 634160f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -77
app.py CHANGED
@@ -31,13 +31,15 @@ st.markdown("""
31
  font-size: 18px;
32
  font-weight: bold;
33
  }
34
-
35
- /* Custom borders for the semester input boxes */
36
  .semester-box {
37
  border: 2px solid #003366;
38
- padding: 15px;
39
  border-radius: 8px;
40
  margin-top: 10px;
 
 
41
  }
42
 
43
  .input-field {
@@ -45,17 +47,19 @@ st.markdown("""
45
  border-radius: 8px;
46
  padding: 8px;
47
  font-size: 14px;
 
 
48
  }
49
-
50
- .expander-header {
51
- font-size: 16px;
52
- font-weight: bold;
53
- color: #003366;
 
54
  }
55
  </style>
56
  """, unsafe_allow_html=True)
57
 
58
-
59
  # ===== GSheet integration =====
60
  @st.cache_resource
61
  def get_gsheet_client():
@@ -112,18 +116,6 @@ def save_to_gsheet(name, student_id, major, prediction, semester_data, sheet_nam
112
  # Append data to the sheet
113
  sheet.append_row(data_row)
114
 
115
-
116
- # ===== List all sheet names =====
117
- # def list_sheet_names(sheet_id):
118
- # client = get_gsheet_client()
119
- # sheet = client.open_by_key(sheet_id)
120
-
121
- # # List all sheet names
122
- # sheet_names = [worksheet.title for worksheet in sheet.worksheets()]
123
- # return sheet_names
124
-
125
-
126
-
127
  # ===== HEADER =====
128
  st.markdown("<h1 style='text-align: center; color: #003366;'>🎓 DỰ ĐOÁN KHẢ NĂNG TỐT NGHIỆP ĐÚNG HẠN</h1>", unsafe_allow_html=True)
129
  st.markdown("<h4 style='text-align: center; color: #666;'>Áp dụng cho sinh viên năm 3</h4>", unsafe_allow_html=True)
@@ -153,7 +145,6 @@ sample_cntt_example_full = {
153
  }
154
 
155
  # ===== Ví dụ mẫu cho mô hình "Dùng mô hình đơn giản" =====
156
- # ===== Ví dụ cho mô hình "Dùng mô hình đơn giản" cho Kinh tế =====
157
  sample_kinhte_example_simple = {
158
  "name": "Trần Thị B",
159
  "student_id": "11418092",
@@ -168,8 +159,6 @@ sample_kinhte_example_simple = {
168
  ]
169
  }
170
 
171
-
172
- # ===== Ví dụ cho mô hình "Dùng mô hình đơn giản" cho CNTT =====
173
  # ===== Ví dụ cho mô hình "Dùng mô hình đơn giản" cho CNTT =====
174
  sample_cntt_example_simple = {
175
  "name": "Nguyễn Văn B",
@@ -185,21 +174,6 @@ sample_cntt_example_simple = {
185
  ]
186
  }
187
 
188
- # ===== Ví dụ cho mô hình "Dùng mô hình đơn giản" cho Kinh tế =====
189
- sample_kinhte_example_full = {
190
- "name": "Trần Thị C",
191
- "student_id": "11418093",
192
- "major": "Kinh tế",
193
- "semester_data": [
194
- 0, 0, 0, 0, 16, 6, 6, 7.00, 1,
195
- 0, 0, 0, 0, 18, 7, 7, 8.20, 1,
196
- 0, 0, 0, 0, 17, 7, 7, 7.80, 1,
197
- 0, 0, 0, 0, 17, 7, 6, 7.90, 1,
198
- 0, 0, 0, 0, 19, 8, 5, 8.10, 0,
199
- 0, 0, 8, 2, 19, 7, 6, 7.30, 1
200
- ]
201
- }
202
-
203
  # ===== Thông tin cá nhân =====
204
  if sample_option == "Dùng ví dụ mẫu ngành Công nghệ thông tin":
205
  name = st.text_input("👤 Họ và tên", value=sample_cntt_example_full["name"])
@@ -217,38 +191,6 @@ else:
217
  st.write("---")
218
 
219
  # ===== Nhập thông tin học kỳ =====
220
- def input_semester(semester_label, default_values=None):
221
- with st.expander(f"📖 {semester_label}", expanded=True):
222
- col1, col2 = st.columns(2)
223
- with col1:
224
- somon0thi = st.number_input("Số môn không thi", 0, value=default_values[0] if default_values else 0, key=f"sm0_{semester_label}")
225
- sotc0thi = st.number_input("Số tín chỉ không thi", 0, value=default_values[1] if default_values else 0, key=f"tc0_{semester_label}")
226
- sotcno = st.number_input("Số tín chỉ nợ", 0, value=default_values[2] if default_values else 0, key=f"tcno_{semester_label}")
227
- mhno = st.number_input("Số môn không đạt", 0, value=default_values[3] if default_values else 0, key=f"mhno_{semester_label}")
228
- try:
229
- default_tc_qua = default_values[4] - default_values[2] if default_values and len(default_values) >= 5 else 0
230
- except:
231
- default_tc_qua = 0
232
- sotc_qua = st.number_input("Số tín chỉ qua môn", 0, value=default_tc_qua, key=f"tcqua_{semester_label}")
233
- with col2:
234
- TCHK = st.number_input("Tổng tín chỉ học kỳ", 0, value=default_values[4] if default_values else 0, key=f"tchk_{semester_label}")
235
- smhk = st.number_input("Số môn học kỳ", 0, value=default_values[5] if default_values else 0, key=f"smhk_{semester_label}")
236
- mhpass = st.number_input("Số môn đạt", 0, value=default_values[6] if default_values else 0, key=f"mhpass_{semester_label}")
237
- TBCHK = st.number_input("GPA", 0.0, 10.0, value=default_values[7] if default_values else 0.0, step=0.01, key=f"gpa_{semester_label}")
238
- xep_loai_selected = st.selectbox("Xếp loại", list(range(7)), index=default_values[8] if default_values else 0, key=f"xeploai_{semester_label}")
239
- return [somon0thi, sotc0thi, sotcno, mhno, TCHK, smhk, mhpass, TBCHK, xep_loai_selected, sotc_qua]
240
-
241
- def input_important_features(semester_label, default_values=None):
242
- with st.expander(f"📘 {semester_label}", expanded=True):
243
- col1, col2 = st.columns(2)
244
- with col1:
245
- sotc_qua = st.number_input("Số tín chỉ đạt", 0, value=default_values[0] if default_values else 0, key=f"tcqua_imp_{semester_label}")
246
- sotcno = st.number_input("Số tín chỉ nợ", 0, value=default_values[1] if default_values else 0, key=f"tcno_imp_{semester_label}")
247
- with col2:
248
- TBCHK = st.number_input("Điểm trung bình", 0.0, 10.0, value=default_values[2] if default_values else 0.0, step=0.01, key=f"gpa_imp_{semester_label}")
249
- return [sotc_qua, sotcno, TBCHK]
250
-
251
- # ===== Giao diện theo mô hình =====
252
  data = []
253
  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"]
254
 
@@ -305,7 +247,6 @@ if st.button("🎯 DỰ BÁO"):
305
  prediction = model_important.predict(final_features)
306
  sheet_name = "Trang tính2" # For full data model, save to Trang tính1
307
 
308
-
309
  if prediction[0] == 1:
310
  st.success(f"🎉 Chúc mừng bạn {name} - {major}! Bạn có khả năng tốt nghiệp đúng hạn!")
311
  st.balloons()
@@ -313,10 +254,5 @@ if st.button("🎯 DỰ BÁO"):
313
  st.error(f"⚠️ Bạn {name} - {major} cần cố gắng hơn! Có nguy cơ trễ hạn.")
314
  st.snow()
315
 
316
- # # Debugging: List all sheet names
317
- # sheet_id = "1i7bDNvLVLXN93_e-FN0JLzpg1jb64Z_aEuyPjIfwbdQ" # Use your actual Spreadsheet ID
318
- # sheet_names = list_sheet_names(sheet_id)
319
- # st.write("Available sheet names:", sheet_names)
320
-
321
  # Ghi log lên Google Sheets
322
  save_to_gsheet(name, student_id, major, prediction, data,sheet_name) # Pass data to save function
 
31
  font-size: 18px;
32
  font-weight: bold;
33
  }
34
+
35
+ /* Custom layout for semester input boxes */
36
  .semester-box {
37
  border: 2px solid #003366;
38
+ padding: 10px;
39
  border-radius: 8px;
40
  margin-top: 10px;
41
+ width: 50%; /* Adjust width for a shorter input box */
42
+ display: inline-block;
43
  }
44
 
45
  .input-field {
 
47
  border-radius: 8px;
48
  padding: 8px;
49
  font-size: 14px;
50
+ width: 100%; /* Ensure inputs are responsive to box size */
51
+ margin-bottom: 10px;
52
  }
53
+
54
+ /* Position the label and the input box side by side */
55
+ .input-label {
56
+ display: inline-block;
57
+ width: 40%; /* Label width */
58
+ margin-right: 10px;
59
  }
60
  </style>
61
  """, unsafe_allow_html=True)
62
 
 
63
  # ===== GSheet integration =====
64
  @st.cache_resource
65
  def get_gsheet_client():
 
116
  # Append data to the sheet
117
  sheet.append_row(data_row)
118
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  # ===== HEADER =====
120
  st.markdown("<h1 style='text-align: center; color: #003366;'>🎓 DỰ ĐOÁN KHẢ NĂNG TỐT NGHIỆP ĐÚNG HẠN</h1>", unsafe_allow_html=True)
121
  st.markdown("<h4 style='text-align: center; color: #666;'>Áp dụng cho sinh viên năm 3</h4>", unsafe_allow_html=True)
 
145
  }
146
 
147
  # ===== Ví dụ mẫu cho mô hình "Dùng mô hình đơn giản" =====
 
148
  sample_kinhte_example_simple = {
149
  "name": "Trần Thị B",
150
  "student_id": "11418092",
 
159
  ]
160
  }
161
 
 
 
162
  # ===== Ví dụ cho mô hình "Dùng mô hình đơn giản" cho CNTT =====
163
  sample_cntt_example_simple = {
164
  "name": "Nguyễn Văn B",
 
174
  ]
175
  }
176
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
177
  # ===== Thông tin cá nhân =====
178
  if sample_option == "Dùng ví dụ mẫu ngành Công nghệ thông tin":
179
  name = st.text_input("👤 Họ và tên", value=sample_cntt_example_full["name"])
 
191
  st.write("---")
192
 
193
  # ===== Nhập thông tin học kỳ =====
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
  data = []
195
  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"]
196
 
 
247
  prediction = model_important.predict(final_features)
248
  sheet_name = "Trang tính2" # For full data model, save to Trang tính1
249
 
 
250
  if prediction[0] == 1:
251
  st.success(f"🎉 Chúc mừng bạn {name} - {major}! Bạn có khả năng tốt nghiệp đúng hạn!")
252
  st.balloons()
 
254
  st.error(f"⚠️ Bạn {name} - {major} cần cố gắng hơn! Có nguy cơ trễ hạn.")
255
  st.snow()
256
 
 
 
 
 
 
257
  # Ghi log lên Google Sheets
258
  save_to_gsheet(name, student_id, major, prediction, data,sheet_name) # Pass data to save function