MK-316 commited on
Commit
ec30f42
1 Parent(s): 49e2a28

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -16
app.py CHANGED
@@ -64,6 +64,7 @@ col1, col2 = st.columns([2, 1])
64
  # Left column: Current time, input, buttons
65
  with col1:
66
  # Display current time
 
67
  display_current_time()
68
 
69
  # Buttons to Start and Reset the countdown
@@ -82,30 +83,34 @@ with col1:
82
  with col2:
83
  progress_placeholder = st.empty()
84
 
85
- # Timer countdown logic (runs when countdown has started)
86
  if st.session_state.countdown_started and not st.session_state.time_up:
87
- if st.session_state.remaining_time > 0:
88
- # Update the circular progress chart with time in the center
89
  fig = update_progress_circle(st.session_state.remaining_time, st.session_state.start_time)
90
  progress_placeholder.pyplot(fig)
91
 
 
 
 
 
92
  # Update the remaining time
93
  st.session_state.remaining_time -= 1
94
-
95
  # Sleep for a second
96
  time.sleep(1)
 
 
 
97
 
98
- # Rerun the app to update every second
99
- st.experimental_rerun()
100
- else:
101
- # When the countdown finishes, display "Time's Up!" inside the circle
102
- st.session_state.time_up = True
103
- fig = update_progress_circle(0, st.session_state.start_time)
104
- progress_placeholder.pyplot(fig)
105
- countdown_placeholder.write("⏰ **Time's Up!**")
106
 
107
- # Play the sound using Streamlit's audio player
108
- audio_file = open("timesup.mp3", "rb")
109
- st.audio(audio_file.read(), format="audio/mp3")
110
 
111
- st.session_state.countdown_started = False
 
64
  # Left column: Current time, input, buttons
65
  with col1:
66
  # Display current time
67
+ current_time_placeholder = st.empty()
68
  display_current_time()
69
 
70
  # Buttons to Start and Reset the countdown
 
83
  with col2:
84
  progress_placeholder = st.empty()
85
 
86
+ # Timer countdown loop (only runs when countdown has started)
87
  if st.session_state.countdown_started and not st.session_state.time_up:
88
+ while st.session_state.remaining_time > 0:
89
+ # Display the circular progress chart with time in the center
90
  fig = update_progress_circle(st.session_state.remaining_time, st.session_state.start_time)
91
  progress_placeholder.pyplot(fig)
92
 
93
+ # Display countdown time
94
+ minutes, seconds = divmod(st.session_state.remaining_time, 60)
95
+ countdown_placeholder.write(f"**Remaining Time:** {int(minutes):02d}:{int(seconds):02d}")
96
+
97
  # Update the remaining time
98
  st.session_state.remaining_time -= 1
99
+
100
  # Sleep for a second
101
  time.sleep(1)
102
+
103
+ # Update current time
104
+ display_current_time()
105
 
106
+ # When the countdown finishes
107
+ st.session_state.time_up = True
108
+ fig = update_progress_circle(0, st.session_state.start_time)
109
+ progress_placeholder.pyplot(fig)
110
+ countdown_placeholder.write("⏰ **Time's Up!**")
 
 
 
111
 
112
+ # Play the sound using Streamlit's audio player
113
+ audio_file = open("timesup.mp3", "rb")
114
+ st.audio(audio_file.read(), format="audio/mp3")
115
 
116
+ st.session_state.countdown_started = False