Rathapoom commited on
Commit
9c25e2d
·
verified ·
1 Parent(s): 91a3d4b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +52 -2
app.py CHANGED
@@ -394,6 +394,11 @@ achievements_list = {
394
  # Initial CSS Setup
395
  st.markdown("""
396
  <style>
 
 
 
 
 
397
  /* Base Styles */
398
  @import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@400;600&display=swap');
399
 
@@ -715,8 +720,23 @@ def initialize_audio():
715
  st.session_state.audio_manager = audio_manager
716
  st.session_state.sound_commands = get_sound_commands()
717
 
718
- # Add audio elements to the page
719
- st.markdown(audio_manager.get_audio_html(), unsafe_allow_html=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
720
 
721
  def show_audio_controls():
722
  """Show audio control in sidebar"""
@@ -3468,6 +3488,32 @@ def create_story_pdf():
3468
  logging.error(f"Error creating PDF: {str(e)}")
3469
  raise
3470
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3471
  # === 6. MAIN APPLICATION LOGIC ===
3472
  def main():
3473
  try:
@@ -3477,6 +3523,10 @@ def main():
3477
 
3478
  # Initialize audio system
3479
  initialize_audio()
 
 
 
 
3480
 
3481
  # Initialize ending system state if not exists
3482
  if 'ending_mode' not in st.session_state:
 
394
  # Initial CSS Setup
395
  st.markdown("""
396
  <style>
397
+ /* Hide audio elements */
398
+ .hide-tag {
399
+ display: none !important;
400
+ }
401
+
402
  /* Base Styles */
403
  @import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@400;600&display=swap');
404
 
 
720
  st.session_state.audio_manager = audio_manager
721
  st.session_state.sound_commands = get_sound_commands()
722
 
723
+ # Add audio elements to the page using st.markdown with hide-tag class
724
+ st.markdown("""
725
+ <style>
726
+ .hide-tag {
727
+ display: none;
728
+ }
729
+ </style>
730
+ """, unsafe_allow_html=True)
731
+
732
+ st.markdown(
733
+ f"""
734
+ <div class="hide-tag">
735
+ {audio_manager.get_audio_html()}
736
+ </div>
737
+ """,
738
+ unsafe_allow_html=True
739
+ )
740
 
741
  def show_audio_controls():
742
  """Show audio control in sidebar"""
 
3488
  logging.error(f"Error creating PDF: {str(e)}")
3489
  raise
3490
 
3491
+ def check_audio_system():
3492
+ """Check if audio system is working properly"""
3493
+ try:
3494
+ if 'audio_manager' in st.session_state:
3495
+ # ตรวจสอบว่า audio elements ถูกโหลดสำเร็จ
3496
+ js_check = """
3497
+ <script>
3498
+ function checkAudioElements() {
3499
+ const elements = ['bgm', 'sound_submit', 'sound_achievement', 'sound_complete'];
3500
+ for (let id of elements) {
3501
+ if (!document.getElementById(id)) {
3502
+ console.error(`Audio element ${id} not found`);
3503
+ return false;
3504
+ }
3505
+ }
3506
+ return true;
3507
+ }
3508
+ window.audioSystemWorking = checkAudioElements();
3509
+ </script>
3510
+ """
3511
+ st.markdown(js_check, unsafe_allow_html=True)
3512
+ return True
3513
+ except Exception as e:
3514
+ logging.error(f"Error checking audio system: {str(e)}")
3515
+ return False
3516
+
3517
  # === 6. MAIN APPLICATION LOGIC ===
3518
  def main():
3519
  try:
 
3523
 
3524
  # Initialize audio system
3525
  initialize_audio()
3526
+
3527
+ # Check audio system
3528
+ if not check_audio_system():
3529
+ st.warning("ระบบเสียงอาจทำงานไม่สมบูรณ์ แต่คุณยังสามารถใช้งานแอพได้")
3530
 
3531
  # Initialize ending system state if not exists
3532
  if 'ending_mode' not in st.session_state: