MK-316 commited on
Commit
ab4b2be
1 Parent(s): a94c22f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -32,12 +32,22 @@ def display_current_time(current_time_placeholder):
32
  )
33
 
34
  # Function to update the progress circle
35
- def update_progress_circle(remaining_time, total_time):
36
  fig, ax = plt.subplots(figsize=(2, 2)) # Smaller figure size to fit layout
37
- fraction_completed = remaining_time / total_time if total_time > 0 else 0
38
- ax.pie([fraction_completed, 1 - fraction_completed], colors=['#5785A4', '#D5DEDD'], startangle=90, counterclock=False, wedgeprops=dict(width=0.3))
39
- minutes, seconds = divmod(remaining_time, 60)
40
- ax.text(0, 0, f"{int(minutes):02d}:{int(seconds):02d}", fontsize=14, va='center', ha='center') # Remaining time
 
 
 
 
 
 
 
 
 
 
41
  ax.set_aspect('equal')
42
  return fig
43
 
@@ -104,7 +114,7 @@ if st.session_state.countdown_started and not st.session_state.time_up:
104
 
105
  # When the countdown finishes
106
  st.session_state.time_up = True
107
- fig = update_progress_circle(0, st.session_state.start_time)
108
  progress_placeholder.pyplot(fig)
109
  countdown_placeholder.write("⏰ **Time's Up!**")
110
 
 
32
  )
33
 
34
  # Function to update the progress circle
35
+ def update_progress_circle(remaining_time, total_time, time_up=False):
36
  fig, ax = plt.subplots(figsize=(2, 2)) # Smaller figure size to fit layout
37
+
38
+ if time_up:
39
+ # Show "Time's Up!" in the center of the circle
40
+ ax.pie([1], colors=['#6d8c9c'], startangle=90, counterclock=False, wedgeprops=dict(width=0.3))
41
+ ax.text(0, 0, "Time's Up!", fontsize=14, va='center', ha='center', color="red") # "Time's Up!" message inside the circle
42
+ else:
43
+ # Calculate the proportion of remaining time
44
+ fraction_completed = remaining_time / total_time if total_time > 0 else 0
45
+ ax.pie([fraction_completed, 1 - fraction_completed], colors=['#5785A4', '#D5DEDD'], startangle=90, counterclock=False, wedgeprops=dict(width=0.3))
46
+
47
+ # Format and add remaining time as text in the center of the circle
48
+ minutes, seconds = divmod(remaining_time, 60)
49
+ ax.text(0, 0, f"{int(minutes):02d}:{int(seconds):02d}", fontsize=14, va='center', ha='center') # Remaining time
50
+
51
  ax.set_aspect('equal')
52
  return fig
53
 
 
114
 
115
  # When the countdown finishes
116
  st.session_state.time_up = True
117
+ fig = update_progress_circle(0, st.session_state.start_time, time_up=True) # Add "Time's Up!" message
118
  progress_placeholder.pyplot(fig)
119
  countdown_placeholder.write("⏰ **Time's Up!**")
120