JirasakJo commited on
Commit
c602184
·
verified ·
1 Parent(s): 962c611

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -40
app.py CHANGED
@@ -213,10 +213,6 @@ def display_chat_history():
213
  </div>
214
  """, unsafe_allow_html=True)
215
 
216
- # # Initialize global state
217
- # if 'all_history' not in st.session_state:
218
- # st.session_state.all_history = []
219
-
220
  def main():
221
  # Page config
222
  st.set_page_config(
@@ -235,7 +231,7 @@ def main():
235
 
236
  if 'chat_history' not in st.session_state:
237
  st.session_state.chat_history = []
238
-
239
  # Load QA history at startup
240
  if 'qa_history_loaded' not in st.session_state:
241
  st.session_state.qa_history_loaded = True
@@ -245,7 +241,6 @@ def main():
245
  st.markdown("""
246
  <div style="text-align: center; padding: 2rem 0;">
247
  <h1>🎓 ระบบค้นหาข้อมูลปฏิทินการศึกษา</h1>
248
- <p style="font-size: 1.2rem; color: #666;">บัณฑิตวิทยาลัย มหาวิทยาลัยศรีนครินทรวิโรฒ</p>
249
  </div>
250
  """, unsafe_allow_html=True)
251
 
@@ -254,7 +249,6 @@ def main():
254
  with st.spinner("กำลังเริ่มต้นระบบ..."):
255
  st.session_state.pipeline = initialize_pipeline()
256
 
257
- # Layout setup
258
  chat_col, info_col = st.columns([7, 3])
259
 
260
  with chat_col:
@@ -264,10 +258,8 @@ def main():
264
 
265
  # Query input section
266
  st.markdown("""
267
- <label for="query_input" style="font-size: 1.2rem; font-weight: 600; margin-bottom: 1rem; display: block;">
268
- <span style="color: #000000; border-left: 4px solid #1E3A8A; padding-left: 0.8rem;">
269
- โปรดระบุคำถามเกี่ยวกับปฏิทินการศึกษา:
270
- </span>
271
  </label>
272
  """, unsafe_allow_html=True)
273
 
@@ -277,7 +269,7 @@ def main():
277
  key="query_input"
278
  )
279
 
280
- # Button layout
281
  col1, col2, col3 = st.columns([1, 1, 4])
282
 
283
  with col1:
@@ -295,28 +287,18 @@ def main():
295
  use_container_width=True,
296
  key="clear_history_button"
297
  )
298
-
299
  # Process query
300
  if send_query and query:
301
  if st.session_state.pipeline is None:
302
  st.error("❌ ไม่สามารถเชื่อมต่อกับระบบได้ กรุณาลองใหม่อีกครั้ง")
303
  return
304
-
305
  add_to_history("user", query)
306
 
307
  try:
308
  with st.spinner("🔍 กำลังค้นหาคำตอบ..."):
309
  result = st.session_state.pipeline.process_query(query)
310
- answer = result["answer"]
311
- add_to_history("assistant", answer)
312
-
313
- # Save QA pair to history
314
- history_entry = add_to_qa_history(query, answer)
315
- if st.session_state.github_sync_enabled:
316
- if save_qa_history(history_entry):
317
- print("Successfully saved QA history to GitHub")
318
- else:
319
- print("Failed to save QA history to GitHub")
320
 
321
  with st.expander("📚 แสดงข้อมูลอ้างอิง", expanded=False):
322
  for i, doc in enumerate(result["documents"], 1):
@@ -337,28 +319,29 @@ def main():
337
 
338
  elif send_query and not query:
339
  st.warning("⚠️ กรุณาระบุคำถาม")
340
-
341
- # Clear history
342
- if clear_history:
343
- st.session_state.chat_history = []
344
- clear_qa_history() # This function handles both local and remote clearing
345
- st.rerun()
346
 
 
 
 
 
 
 
 
347
  # System information
348
  st.markdown("""
349
  <div style="background-color: #F9FAFB; padding: 1.5rem; border-radius: 12px; margin-bottom: 2rem;">
350
  <h3 style="color: #1E3A8A;">ℹ️ เกี่ยวกับระบบ</h3>
351
- <p style="color: #000000;">
352
  ระบบนี้ใช้เทคโนโลยี <strong>RAG (Retrieval-Augmented Generation)</strong>
353
  ในการค้นหาและตอบคำถามเกี่ยวกับปฏิทินการศึกษา
354
  </p>
355
  <h4 style="color: #1E3A8A; margin-top: 1rem;">สามารถสอบถามข้อมูลเกี่ยวกับ:</h4>
356
  <ul style="list-style-type: none; padding-left: 0;">
357
- <li style="color: #000000; margin-bottom: 0.5rem;">📅 กำหนดการต่างๆ ในปฏิทินการศึกษา</li>
358
- <li style="color: #000000; margin-bottom: 0.5rem;">🎯 วันสำคัญและกิจกรรม</li>
359
- <li style="color: #000000; margin-bottom: 0.5rem;">📝 การลงทะเบียนเรียน</li>
360
- <li style="color: #000000; margin-bottom: 0.5rem;">📚 กำหนดการสอบ</li>
361
- <li style="color: #000000; margin-bottom: 0.5rem;">🏖️ วันหยุดการศึกษา</li>
362
  </ul>
363
  </div>
364
  """, unsafe_allow_html=True)
@@ -368,16 +351,16 @@ def main():
368
  <div style="background-color: #f9fafb; padding: 1.5rem; border-radius: 12px;">
369
  <h3 style="color: #1E3A8A;">🔄 สถานะระบบ</h3>
370
  <div style="margin-top: 1rem;">
371
- <p><strong style="color: #000000;">⏰ เวลาปัจจุบัน:</strong><br>
372
- <span style="color: #000000;">{}</span></p>
373
- <p><strong style="color: #000000;">📡 สถานะระบบ:</strong><br>
374
  <span class="status-indicator {}">
375
  {} {}
376
  </span></p>
377
  </div>
378
  </div>
379
  """.format(
380
- (datetime.now() + timedelta(hours=7)).strftime('%Y-%m-%d %H:%M:%S'),
381
  "status-online" if st.session_state.pipeline else "status-offline",
382
  "🟢" if st.session_state.pipeline else "🔴",
383
  "พร้อมใช้งาน" if st.session_state.pipeline else "ไม่พร้อมใช้งาน"
 
213
  </div>
214
  """, unsafe_allow_html=True)
215
 
 
 
 
 
216
  def main():
217
  # Page config
218
  st.set_page_config(
 
231
 
232
  if 'chat_history' not in st.session_state:
233
  st.session_state.chat_history = []
234
+
235
  # Load QA history at startup
236
  if 'qa_history_loaded' not in st.session_state:
237
  st.session_state.qa_history_loaded = True
 
241
  st.markdown("""
242
  <div style="text-align: center; padding: 2rem 0;">
243
  <h1>🎓 ระบบค้นหาข้อมูลปฏิทินการศึกษา</h1>
 
244
  </div>
245
  """, unsafe_allow_html=True)
246
 
 
249
  with st.spinner("กำลังเริ่มต้นระบบ..."):
250
  st.session_state.pipeline = initialize_pipeline()
251
 
 
252
  chat_col, info_col = st.columns([7, 3])
253
 
254
  with chat_col:
 
258
 
259
  # Query input section
260
  st.markdown("""
261
+ <label for="query_input" style="font-size: 1.2rem; font-weight: bold; color: black;">
262
+ <span style="color: white; background-color: yellow; padding: 0 0.2rem;">โปรดระบุคำถามเกี่ยวกับ ปฏิทินการศึกษา:</span>
 
 
263
  </label>
264
  """, unsafe_allow_html=True)
265
 
 
269
  key="query_input"
270
  )
271
 
272
+ # Button layout inside main() function
273
  col1, col2, col3 = st.columns([1, 1, 4])
274
 
275
  with col1:
 
287
  use_container_width=True,
288
  key="clear_history_button"
289
  )
 
290
  # Process query
291
  if send_query and query:
292
  if st.session_state.pipeline is None:
293
  st.error("❌ ไม่สามารถเชื่อมต่อกับระบบได้ กรุณาลองใหม่อีกครั้ง")
294
  return
295
+
296
  add_to_history("user", query)
297
 
298
  try:
299
  with st.spinner("🔍 กำลังค้นหาคำตอบ..."):
300
  result = st.session_state.pipeline.process_query(query)
301
+ add_to_history("assistant", result["answer"])
 
 
 
 
 
 
 
 
 
302
 
303
  with st.expander("📚 แสดงข้อมูลอ้างอิง", expanded=False):
304
  for i, doc in enumerate(result["documents"], 1):
 
319
 
320
  elif send_query and not query:
321
  st.warning("⚠️ กรุณาระบุคำถาม")
 
 
 
 
 
 
322
 
323
+ # Handle clear history action
324
+ if clear_history:
325
+ st.session_state.chat_history = []
326
+ clear_qa_history()
327
+ st.rerun()
328
+
329
+ with info_col:
330
  # System information
331
  st.markdown("""
332
  <div style="background-color: #F9FAFB; padding: 1.5rem; border-radius: 12px; margin-bottom: 2rem;">
333
  <h3 style="color: #1E3A8A;">ℹ️ เกี่ยวกับระบบ</h3>
334
+ <p style="color: #ff0015;">
335
  ระบบนี้ใช้เทคโนโลยี <strong>RAG (Retrieval-Augmented Generation)</strong>
336
  ในการค้นหาและตอบคำถามเกี่ยวกับปฏิทินการศึกษา
337
  </p>
338
  <h4 style="color: #1E3A8A; margin-top: 1rem;">สามารถสอบถามข้อมูลเกี่ยวกับ:</h4>
339
  <ul style="list-style-type: none; padding-left: 0;">
340
+ <li>📅 กำหนดการต่างๆ ในปฏิทินการศึกษา</li>
341
+ <li>🎯 วันสำคัญและกิจกรรม</li>
342
+ <li>📝 การลงทะเบียนเรียน</li>
343
+ <li>📚 กำหนดการสอบ</li>
344
+ <li>🏖️ วันหยุดการศึกษา</li>
345
  </ul>
346
  </div>
347
  """, unsafe_allow_html=True)
 
351
  <div style="background-color: #f9fafb; padding: 1.5rem; border-radius: 12px;">
352
  <h3 style="color: #1E3A8A;">🔄 สถานะระบบ</h3>
353
  <div style="margin-top: 1rem;">
354
+ <p><strong>⏰ เวลาปัจจุบัน:</strong><br>
355
+ {}</p>
356
+ <p><strong>📡 สถานะระบบ:</strong><br>
357
  <span class="status-indicator {}">
358
  {} {}
359
  </span></p>
360
  </div>
361
  </div>
362
  """.format(
363
+ (datetime.now() + timedelta(hours=6)).strftime('%Y-%m-%d %H:%M:%S'),
364
  "status-online" if st.session_state.pipeline else "status-offline",
365
  "🟢" if st.session_state.pipeline else "🔴",
366
  "พร้อมใช้งาน" if st.session_state.pipeline else "ไม่พร้อมใช้งาน"