Upload app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,8 @@
|
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
import time
|
|
|
|
|
|
|
| 6 |
from typing import Tuple
|
| 7 |
|
| 8 |
import gradio as gr
|
|
@@ -12,6 +14,27 @@ from egg_timing import DONENESS_BASE_SECONDS, calculate_cook_seconds, format_mm_
|
|
| 12 |
DEFAULT_DONENESS = next(iter(DONENESS_BASE_SECONDS))
|
| 13 |
DEFAULT_EGG_COUNT = 2
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
def _build_status(stage: str, egg_count: int, doneness: str, total_seconds: int) -> str:
|
| 17 |
if stage == "idle":
|
|
@@ -35,6 +58,15 @@ def _build_status(stage: str, egg_count: int, doneness: str, total_seconds: int)
|
|
| 35 |
|
| 36 |
|
| 37 |
def _button_visibility(stage: str):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
return (
|
| 39 |
gr.update(visible=stage == "idle"), # start
|
| 40 |
gr.update(visible=stage == "boil"), # done boil
|
|
@@ -47,6 +79,15 @@ def _button_visibility(stage: str):
|
|
| 47 |
def start_flow(egg_count: int, doneness: str):
|
| 48 |
total_seconds = calculate_cook_seconds(egg_count, doneness)
|
| 49 |
stage = "boil"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
return (
|
| 51 |
stage,
|
| 52 |
total_seconds,
|
|
@@ -61,6 +102,15 @@ def start_flow(egg_count: int, doneness: str):
|
|
| 61 |
|
| 62 |
def to_simmer(egg_count: int, doneness: str, total_seconds: int):
|
| 63 |
stage = "simmer"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
return (
|
| 65 |
stage,
|
| 66 |
_build_status(stage, egg_count, doneness, total_seconds),
|
|
@@ -70,6 +120,15 @@ def to_simmer(egg_count: int, doneness: str, total_seconds: int):
|
|
| 70 |
|
| 71 |
def to_add_eggs(egg_count: int, doneness: str, total_seconds: int):
|
| 72 |
stage = "add_eggs"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
return (
|
| 74 |
stage,
|
| 75 |
_build_status(stage, egg_count, doneness, total_seconds),
|
|
@@ -80,6 +139,15 @@ def to_add_eggs(egg_count: int, doneness: str, total_seconds: int):
|
|
| 80 |
def begin_countdown(egg_count: int, doneness: str, total_seconds: int):
|
| 81 |
stage = "countdown"
|
| 82 |
end_timestamp = time.time() + total_seconds
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
return (
|
| 84 |
stage,
|
| 85 |
total_seconds,
|
|
@@ -119,6 +187,15 @@ def tick(
|
|
| 119 |
def reset_ui():
|
| 120 |
stage = "idle"
|
| 121 |
total_seconds = calculate_cook_seconds(1, DEFAULT_DONENESS)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
return (
|
| 123 |
stage,
|
| 124 |
total_seconds,
|
|
|
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
import time
|
| 6 |
+
import json
|
| 7 |
+
import uuid
|
| 8 |
from typing import Tuple
|
| 9 |
|
| 10 |
import gradio as gr
|
|
|
|
| 14 |
DEFAULT_DONENESS = next(iter(DONENESS_BASE_SECONDS))
|
| 15 |
DEFAULT_EGG_COUNT = 2
|
| 16 |
|
| 17 |
+
DEBUG_LOG_PATH = "/Users/Kenchong/Documents/Cursor timer app/.cursor/debug-b13734.log"
|
| 18 |
+
DEBUG_SESSION_ID = "b13734"
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def _debug_log(run_id: str, hypothesis_id: str, location: str, message: str, data: dict) -> None:
|
| 22 |
+
payload = {
|
| 23 |
+
"sessionId": DEBUG_SESSION_ID,
|
| 24 |
+
"runId": run_id,
|
| 25 |
+
"hypothesisId": hypothesis_id,
|
| 26 |
+
"id": f"log_{int(time.time() * 1000)}_{uuid.uuid4().hex[:8]}",
|
| 27 |
+
"timestamp": int(time.time() * 1000),
|
| 28 |
+
"location": location,
|
| 29 |
+
"message": message,
|
| 30 |
+
"data": data,
|
| 31 |
+
}
|
| 32 |
+
try:
|
| 33 |
+
with open(DEBUG_LOG_PATH, "a", encoding="utf-8") as f:
|
| 34 |
+
f.write(json.dumps(payload, ensure_ascii=False) + "\n")
|
| 35 |
+
except Exception:
|
| 36 |
+
pass
|
| 37 |
+
|
| 38 |
|
| 39 |
def _build_status(stage: str, egg_count: int, doneness: str, total_seconds: int) -> str:
|
| 40 |
if stage == "idle":
|
|
|
|
| 58 |
|
| 59 |
|
| 60 |
def _button_visibility(stage: str):
|
| 61 |
+
# region agent log
|
| 62 |
+
_debug_log(
|
| 63 |
+
run_id="pre-fix",
|
| 64 |
+
hypothesis_id="H1",
|
| 65 |
+
location="app.py:_button_visibility",
|
| 66 |
+
message="Compute button visibility",
|
| 67 |
+
data={"stage": stage},
|
| 68 |
+
)
|
| 69 |
+
# endregion
|
| 70 |
return (
|
| 71 |
gr.update(visible=stage == "idle"), # start
|
| 72 |
gr.update(visible=stage == "boil"), # done boil
|
|
|
|
| 79 |
def start_flow(egg_count: int, doneness: str):
|
| 80 |
total_seconds = calculate_cook_seconds(egg_count, doneness)
|
| 81 |
stage = "boil"
|
| 82 |
+
# region agent log
|
| 83 |
+
_debug_log(
|
| 84 |
+
run_id="pre-fix",
|
| 85 |
+
hypothesis_id="H2",
|
| 86 |
+
location="app.py:start_flow",
|
| 87 |
+
message="Start flow transition",
|
| 88 |
+
data={"egg_count": egg_count, "doneness": doneness, "next_stage": stage, "total_seconds": total_seconds},
|
| 89 |
+
)
|
| 90 |
+
# endregion
|
| 91 |
return (
|
| 92 |
stage,
|
| 93 |
total_seconds,
|
|
|
|
| 102 |
|
| 103 |
def to_simmer(egg_count: int, doneness: str, total_seconds: int):
|
| 104 |
stage = "simmer"
|
| 105 |
+
# region agent log
|
| 106 |
+
_debug_log(
|
| 107 |
+
run_id="pre-fix",
|
| 108 |
+
hypothesis_id="H3",
|
| 109 |
+
location="app.py:to_simmer",
|
| 110 |
+
message="Transition to simmer",
|
| 111 |
+
data={"egg_count": egg_count, "doneness": doneness, "total_seconds": total_seconds, "next_stage": stage},
|
| 112 |
+
)
|
| 113 |
+
# endregion
|
| 114 |
return (
|
| 115 |
stage,
|
| 116 |
_build_status(stage, egg_count, doneness, total_seconds),
|
|
|
|
| 120 |
|
| 121 |
def to_add_eggs(egg_count: int, doneness: str, total_seconds: int):
|
| 122 |
stage = "add_eggs"
|
| 123 |
+
# region agent log
|
| 124 |
+
_debug_log(
|
| 125 |
+
run_id="pre-fix",
|
| 126 |
+
hypothesis_id="H4",
|
| 127 |
+
location="app.py:to_add_eggs",
|
| 128 |
+
message="Transition to add_eggs",
|
| 129 |
+
data={"egg_count": egg_count, "doneness": doneness, "total_seconds": total_seconds, "next_stage": stage},
|
| 130 |
+
)
|
| 131 |
+
# endregion
|
| 132 |
return (
|
| 133 |
stage,
|
| 134 |
_build_status(stage, egg_count, doneness, total_seconds),
|
|
|
|
| 139 |
def begin_countdown(egg_count: int, doneness: str, total_seconds: int):
|
| 140 |
stage = "countdown"
|
| 141 |
end_timestamp = time.time() + total_seconds
|
| 142 |
+
# region agent log
|
| 143 |
+
_debug_log(
|
| 144 |
+
run_id="pre-fix",
|
| 145 |
+
hypothesis_id="H5",
|
| 146 |
+
location="app.py:begin_countdown",
|
| 147 |
+
message="Countdown started",
|
| 148 |
+
data={"egg_count": egg_count, "doneness": doneness, "total_seconds": total_seconds, "next_stage": stage},
|
| 149 |
+
)
|
| 150 |
+
# endregion
|
| 151 |
return (
|
| 152 |
stage,
|
| 153 |
total_seconds,
|
|
|
|
| 187 |
def reset_ui():
|
| 188 |
stage = "idle"
|
| 189 |
total_seconds = calculate_cook_seconds(1, DEFAULT_DONENESS)
|
| 190 |
+
# region agent log
|
| 191 |
+
_debug_log(
|
| 192 |
+
run_id="pre-fix",
|
| 193 |
+
hypothesis_id="H2",
|
| 194 |
+
location="app.py:reset_ui",
|
| 195 |
+
message="Reset UI",
|
| 196 |
+
data={"next_stage": stage, "default_doneness": DEFAULT_DONENESS, "total_seconds": total_seconds},
|
| 197 |
+
)
|
| 198 |
+
# endregion
|
| 199 |
return (
|
| 200 |
stage,
|
| 201 |
total_seconds,
|