Update whoop_gradio_server.py
Browse files- whoop_gradio_server.py +1 -26
whoop_gradio_server.py
CHANGED
|
@@ -109,31 +109,6 @@ def get_sleeps_gr():
|
|
| 109 |
start_date = (datetime.now() - timedelta(days=10)).strftime("%Y-%m-%d")
|
| 110 |
sleeps = whoop_client.get_sleep_collection(start_date, end_date)
|
| 111 |
return sleeps
|
| 112 |
-
# if not sleeps:
|
| 113 |
-
# return "⚠️ No sleep data available."
|
| 114 |
-
|
| 115 |
-
# summary = "\n\n".join([
|
| 116 |
-
# f"😴 Sleep {i+1}:\nScore: {s.get('score', {}).get('sleep_score', 'N/A')}, "
|
| 117 |
-
# f"Duration: {s.get('sleep_duration') // 60 if s.get('sleep_duration') else 'N/A'} min"
|
| 118 |
-
# for i, s in enumerate(sleeps)
|
| 119 |
-
# ])
|
| 120 |
-
# return summary
|
| 121 |
-
# except Exception as e:
|
| 122 |
-
# return f"❌ Error fetching sleeps: {e}"
|
| 123 |
-
|
| 124 |
-
def format_latest_cycle(raw_text):
|
| 125 |
-
"""
|
| 126 |
-
Formats the raw text returned by get_latest_cycle_gr for display.
|
| 127 |
-
"""
|
| 128 |
-
if raw_text.startswith("❌") or raw_text.startswith("⚠️"):
|
| 129 |
-
return raw_text, ""
|
| 130 |
-
try:
|
| 131 |
-
lines = raw_text.splitlines()
|
| 132 |
-
recovery_score_line = next((line for line in lines if "Recovery Score" in line), "Recovery Score: Not Available")
|
| 133 |
-
full_data = "\n".join(lines[2:]) # skip title and recovery line
|
| 134 |
-
return recovery_score_line, full_data
|
| 135 |
-
except Exception as e:
|
| 136 |
-
return f"❌ Failed to parse cycle: {e}", ""
|
| 137 |
|
| 138 |
# UI definition
|
| 139 |
with gr.Blocks(title="Whoop API Explorer") as demo:
|
|
@@ -166,7 +141,7 @@ with gr.Blocks(title="Whoop API Explorer") as demo:
|
|
| 166 |
|
| 167 |
# Bind actions
|
| 168 |
auth_button.click(fn=initialize_whoop_client_with_input, inputs=[email_input, password_input], outputs=auth_output)
|
| 169 |
-
cycle_button.click(fn=
|
| 170 |
workout_button.click(fn=get_workouts_gr, outputs=workout_output)
|
| 171 |
sleep_button.click(fn=get_sleeps_gr, outputs=sleep_output)
|
| 172 |
|
|
|
|
| 109 |
start_date = (datetime.now() - timedelta(days=10)).strftime("%Y-%m-%d")
|
| 110 |
sleeps = whoop_client.get_sleep_collection(start_date, end_date)
|
| 111 |
return sleeps
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
# UI definition
|
| 114 |
with gr.Blocks(title="Whoop API Explorer") as demo:
|
|
|
|
| 141 |
|
| 142 |
# Bind actions
|
| 143 |
auth_button.click(fn=initialize_whoop_client_with_input, inputs=[email_input, password_input], outputs=auth_output)
|
| 144 |
+
cycle_button.click(fn=get_latest_cycle_gr, outputs=[latest_recovery, cycle_details])
|
| 145 |
workout_button.click(fn=get_workouts_gr, outputs=workout_output)
|
| 146 |
sleep_button.click(fn=get_sleeps_gr, outputs=sleep_output)
|
| 147 |
|