Spaces:
Sleeping
Sleeping
Download server/app.py from Aayan2024/RL_Budget_Planner_env: direct link, hf CLI and curl.
- Browser
- Download file 3.61 kB
-
https://huggingface.co/spaces/Aayan2024/RL_Budget_Planner_env/resolve/main/server/app.py
- Command line
-
hf download hf://spaces/Aayan2024/RL_Budget_Planner_env/server/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Aayan2024/RL_Budget_Planner_env/resolve/main/server/app.py
3.61 kB
| import sys | |
| import os | |
| import uvicorn | |
| sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) | |
| from openenv.core.env_server import create_fastapi_app | |
| from fastapi.responses import HTMLResponse | |
| from models import BudgetAction, BudgetObservation | |
| from server.budget_environment import BudgetEnvironment | |
| app = create_fastapi_app(BudgetEnvironment, BudgetAction, BudgetObservation) | |
| def root(): | |
| return """ | |
| <!doctype html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | |
| <title>Budget Planner RL</title> | |
| <style> | |
| body { font-family: Arial, sans-serif; margin: 24px; max-width: 880px; } | |
| h1 { margin-bottom: 8px; } | |
| .muted { color: #555; margin-top: 0; } | |
| .row { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; margin: 16px 0; } | |
| label { display: grid; gap: 6px; font-size: 14px; } | |
| select, input, button { padding: 8px 10px; font-size: 14px; } | |
| button { cursor: pointer; } | |
| .panel { border: 1px solid #ddd; border-radius: 8px; padding: 12px; margin-top: 12px; } | |
| pre { margin: 0; white-space: pre-wrap; } | |
| </style> | |
| </head> | |
| <body> | |
| <h1>Budget Planner RL</h1> | |
| <p class="muted">Minimal evaluator UI for reset/step interaction.</p> | |
| <div class="row"> | |
| <label> | |
| Task | |
| <select id="taskLevel"> | |
| <option value="easy">easy</option> | |
| <option value="medium">medium</option> | |
| <option value="hard">hard</option> | |
| </select> | |
| </label> | |
| <button id="resetBtn">Reset Episode</button> | |
| </div> | |
| <div class="row"> | |
| <label> | |
| Category | |
| <select id="category"> | |
| <option value="food">food</option> | |
| <option value="rent">rent</option> | |
| <option value="transport">transport</option> | |
| <option value="entertainment">entertainment</option> | |
| <option value="utilities">utilities</option> | |
| <option value="health">health</option> | |
| </select> | |
| </label> | |
| <label> | |
| Amount | |
| <input id="amount" type="number" step="0.01" min="0" value="50" /> | |
| </label> | |
| <button id="stepBtn">Take Step</button> | |
| </div> | |
| <div class="panel"> | |
| <strong>Latest Observation</strong> | |
| <pre id="output">Click "Reset Episode" to start.</pre> | |
| </div> | |
| <script> | |
| const output = document.getElementById('output'); | |
| function show(data) { | |
| output.textContent = JSON.stringify(data, null, 2); | |
| } | |
| async function postJSON(path, payload) { | |
| const res = await fetch(path, { | |
| method: 'POST', | |
| headers: { 'Content-Type': 'application/json' }, | |
| body: JSON.stringify(payload) | |
| }); | |
| const data = await res.json(); | |
| if (!res.ok) { | |
| throw new Error(data.detail || `Request failed: ${res.status}`); | |
| } | |
| return data; | |
| } | |
| document.getElementById('resetBtn').addEventListener('click', async () => { | |
| try { | |
| const task_level = document.getElementById('taskLevel').value; | |
| const data = await postJSON('/reset', { task_level }); | |
| show(data); | |
| } catch (err) { | |
| show({ error: String(err) }); | |
| } | |
| }); | |
| document.getElementById('stepBtn').addEventListener('click', async () => { | |
| try { | |
| const category = document.getElementById('category').value; | |
| const amount = Number(document.getElementById('amount').value); | |
| const data = await postJSON('/step', { action: { category, amount } }); | |
| show(data); | |
| } catch (err) { | |
| show({ error: String(err) }); | |
| } | |
| }); | |
| </script> | |
| </body> | |
| </html> | |
| """ | |
| def health(): | |
| return {"status": "ok"} | |
| def main() -> None: | |
| port = int(os.getenv("PORT", "7860")) | |
| uvicorn.run("server.app:app", host="0.0.0.0", port=port) | |
| if __name__ == "__main__": | |
| main() | |