Spaces:
Sleeping
Sleeping
Upload app.py with huggingface_hub
Browse files
app.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import annotations
|
| 2 |
+
|
| 3 |
+
import gradio as gr
|
| 4 |
+
|
| 5 |
+
from environment.env import WorkLifeFirewallEnv
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def run_episode(policy_style: str):
|
| 9 |
+
env = WorkLifeFirewallEnv(randomize_order=False, seed=42)
|
| 10 |
+
obs = env.reset()
|
| 11 |
+
done = False
|
| 12 |
+
logs = []
|
| 13 |
+
|
| 14 |
+
while not done:
|
| 15 |
+
event = obs["event"]
|
| 16 |
+
if policy_style == "strategic":
|
| 17 |
+
action = (
|
| 18 |
+
"I will send a clear async update, protect focus, and commit a concrete timeline."
|
| 19 |
+
)
|
| 20 |
+
elif policy_style == "people_pleaser":
|
| 21 |
+
action = "Sure, I will do it now."
|
| 22 |
+
else:
|
| 23 |
+
action = "I will handle this with a clear plan."
|
| 24 |
+
|
| 25 |
+
obs, reward, done, info = env.step(action)
|
| 26 |
+
logs.append(f"{event['id']} -> reward {reward:.3f} | action: {action}")
|
| 27 |
+
|
| 28 |
+
state = env.state()
|
| 29 |
+
summary = (
|
| 30 |
+
f"Friday energy: {state['energy_pct']}%\n"
|
| 31 |
+
f"Sprint health: {state['sprint_health_pct']}%\n"
|
| 32 |
+
f"Leave: {state['leave_status']}\n"
|
| 33 |
+
)
|
| 34 |
+
if info.get("components"):
|
| 35 |
+
summary += "\nComponent scores:\n"
|
| 36 |
+
summary += "\n".join([f"- {k}: {v:.3f}" for k, v in info["components"].items()])
|
| 37 |
+
return "\n".join(logs), summary
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
demo = gr.Interface(
|
| 41 |
+
fn=run_episode,
|
| 42 |
+
inputs=gr.Radio(
|
| 43 |
+
choices=["strategic", "balanced", "people_pleaser"],
|
| 44 |
+
value="balanced",
|
| 45 |
+
label="Policy style",
|
| 46 |
+
),
|
| 47 |
+
outputs=[
|
| 48 |
+
gr.Textbox(label="Episode log", lines=18),
|
| 49 |
+
gr.Textbox(label="Outcome"),
|
| 50 |
+
],
|
| 51 |
+
title="Work-Life Firewall",
|
| 52 |
+
description="HF Space demo for boundary-setting environment behavior.",
|
| 53 |
+
)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
if __name__ == "__main__":
|
| 57 |
+
demo.launch()
|