EmilyWitko HF staff commited on
Commit
e8dca06
1 Parent(s): 93f488c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -14
app.py CHANGED
@@ -1,30 +1,48 @@
1
  import gradio as gr
2
- import datetime
3
 
4
  # Initialize counters and logs
5
  total_exercises_completed = 0
6
  days_completed = 0
7
- last_reset = datetime.date.today() - datetime.timedelta(days=1)
8
- exercise_log = {exercise: 0 for exercise in range(1, 9)}
9
 
10
  def reset_tracker():
11
  global total_exercises_completed, days_completed, last_reset, exercise_log
12
- if datetime.date.today() > last_reset:
13
  all_done_today = all(count >= 6 for count in exercise_log.values())
14
  if all_done_today:
15
  days_completed += 1
16
- last_reset = datetime.date.today()
17
- exercise_log = {exercise: 0 for exercise in range(1, 9)}
18
- # Convert dictionaries and counts to strings for display
19
- return str(exercise_log), str(total_exercises_completed), str(days_completed)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  iface = gr.Interface(
22
- fn=reset_tracker,
23
- inputs=gr.Button("Reset Daily Tracker"),
24
  outputs=[
25
- gr.Textbox(label="Exercise Log", lines=10, value="Initial state"),
26
- gr.Textbox(label="Total Exercises Completed", value="0"),
27
- gr.Textbox(label="Days Completed", value="0")
28
- ])
 
 
29
 
30
  iface.launch()
 
1
  import gradio as gr
2
+ from datetime import date, timedelta
3
 
4
  # Initialize counters and logs
5
  total_exercises_completed = 0
6
  days_completed = 0
7
+ last_reset = date.today() - timedelta(days=1)
8
+ exercise_log = {f"Exercise {i+1}": 0 for i in range(8)}
9
 
10
  def reset_tracker():
11
  global total_exercises_completed, days_completed, last_reset, exercise_log
12
+ if date.today() > last_reset:
13
  all_done_today = all(count >= 6 for count in exercise_log.values())
14
  if all_done_today:
15
  days_completed += 1
16
+ last_reset = date.today()
17
+ exercise_log = {f"Exercise {i+1}": 0 for i in range(8)}
18
+ return exercise_log, total_exercises_completed, days_completed
19
+
20
+ def update_exercise(exercise_num):
21
+ global exercise_log, total_exercises_completed
22
+ if date.today() > last_reset:
23
+ reset_tracker()
24
+ exercise_name = f"Exercise {exercise_num}"
25
+ if exercise_log[exercise_name] < 6:
26
+ exercise_log[exercise_name] += 1
27
+ total_exercises_completed += 1
28
+ return exercise_log, total_exercises_completed, days_completed
29
+
30
+ def get_exercise_status():
31
+ global exercise_log, total_exercises_completed, days_completed
32
+ return "\n".join(f"{name}: {count}" for name, count in exercise_log.items()), total_exercises_completed, days_completed
33
+
34
+ reset_button = gr.Button("Reset Daily Tracker")
35
+ exercise_buttons = [gr.Button(f"Exercise {i+1}") for i in range(8)]
36
 
37
  iface = gr.Interface(
38
+ fn=get_exercise_status,
39
+ inputs=[gr.Number(label="Exercise Number", value=1)] + [reset_button] + exercise_buttons,
40
  outputs=[
41
+ gr.Textbox(label="Exercise Log", lines=10, value=""),
42
+ gr.Number(label="Total Exercises Completed"),
43
+ gr.Number(label="Days Completed")
44
+ ],
45
+ live=True
46
+ )
47
 
48
  iface.launch()