Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ from __future__ import annotations
|
|
| 2 |
|
| 3 |
import os
|
| 4 |
import time
|
|
|
|
| 5 |
from functools import lru_cache
|
| 6 |
from threading import Lock
|
| 7 |
from typing import Dict, List, Tuple
|
|
@@ -92,17 +93,32 @@ def _cached_episode(policy_style: str, seed: int, randomize_order: bool) -> Tupl
|
|
| 92 |
|
| 93 |
def run_episode(policy_style: str, seed: int, randomize_order: bool):
|
| 94 |
_throttle_event_requests()
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
|
| 107 |
|
| 108 |
def compare_policies(seed: int, randomize_order: bool):
|
|
|
|
| 2 |
|
| 3 |
import os
|
| 4 |
import time
|
| 5 |
+
import traceback
|
| 6 |
from functools import lru_cache
|
| 7 |
from threading import Lock
|
| 8 |
from typing import Dict, List, Tuple
|
|
|
|
| 93 |
|
| 94 |
def run_episode(policy_style: str, seed: int, randomize_order: bool):
|
| 95 |
_throttle_event_requests()
|
| 96 |
+
try:
|
| 97 |
+
logs, state, components = _cached_episode(policy_style, seed, randomize_order)
|
| 98 |
+
episode_log = "\n".join([
|
| 99 |
+
"Episode started.",
|
| 100 |
+
logs,
|
| 101 |
+
])
|
| 102 |
+
summary = (
|
| 103 |
+
"### Outcome\n"
|
| 104 |
+
f"- Friday energy: **{state['energy_pct']}%**\n"
|
| 105 |
+
f"- Sprint health: **{state['sprint_health_pct']}%**\n"
|
| 106 |
+
f"- Leave status: **{state['leave_status']}**\n"
|
| 107 |
+
)
|
| 108 |
+
comp_rows = [[k, round(v, 3)] for k, v in sorted(components.items())]
|
| 109 |
+
if not comp_rows:
|
| 110 |
+
comp_rows = [["(none)", 0.0]]
|
| 111 |
+
return episode_log, summary, comp_rows
|
| 112 |
+
except Exception as exc:
|
| 113 |
+
episode_log = "Episode failed:\n" + "".join(
|
| 114 |
+
traceback.format_exception(type(exc), exc, exc.__traceback__)
|
| 115 |
+
)
|
| 116 |
+
summary = (
|
| 117 |
+
"### Outcome\n"
|
| 118 |
+
f"- Error: **{type(exc).__name__}**\n"
|
| 119 |
+
f"- Message: **{exc}**\n"
|
| 120 |
+
)
|
| 121 |
+
return episode_log, summary, [["error", 1.0]]
|
| 122 |
|
| 123 |
|
| 124 |
def compare_policies(seed: int, randomize_order: bool):
|