Spaces:
Sleeping
Sleeping
Add HTML landing page at / so HF Space iframe shows useful content
Browse files- server/app.py +115 -1
server/app.py
CHANGED
|
@@ -5,14 +5,17 @@ Exposes the ValidatorEnvironment over HTTP and WebSocket endpoints
|
|
| 5 |
using ``openenv.core.env_server.http_server.create_app``.
|
| 6 |
|
| 7 |
Endpoints created automatically:
|
|
|
|
| 8 |
- POST /reset β Reset the environment
|
| 9 |
- POST /step β Execute an action
|
| 10 |
- GET /state β Get current environment state
|
| 11 |
- GET /health β Health check
|
| 12 |
- WS /ws β WebSocket for persistent sessions
|
| 13 |
-
- GET /docs β Swagger UI
|
| 14 |
"""
|
| 15 |
|
|
|
|
|
|
|
| 16 |
try:
|
| 17 |
from openenv.core.env_server.http_server import create_app
|
| 18 |
except Exception as exc:
|
|
@@ -43,6 +46,117 @@ app = create_app(
|
|
| 43 |
)
|
| 44 |
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
def main(host: str = "0.0.0.0", port: int = 7860) -> None:
|
| 47 |
"""Entry point for ``uv run server`` or direct execution."""
|
| 48 |
import uvicorn
|
|
|
|
| 5 |
using ``openenv.core.env_server.http_server.create_app``.
|
| 6 |
|
| 7 |
Endpoints created automatically:
|
| 8 |
+
- GET / β Landing page (this module)
|
| 9 |
- POST /reset β Reset the environment
|
| 10 |
- POST /step β Execute an action
|
| 11 |
- GET /state β Get current environment state
|
| 12 |
- GET /health β Health check
|
| 13 |
- WS /ws β WebSocket for persistent sessions
|
| 14 |
+
- GET /docs β Swagger UI (interactive β try every endpoint)
|
| 15 |
"""
|
| 16 |
|
| 17 |
+
from fastapi.responses import HTMLResponse
|
| 18 |
+
|
| 19 |
try:
|
| 20 |
from openenv.core.env_server.http_server import create_app
|
| 21 |
except Exception as exc:
|
|
|
|
| 46 |
)
|
| 47 |
|
| 48 |
|
| 49 |
+
_LANDING_HTML = """<!doctype html>
|
| 50 |
+
<html lang="en">
|
| 51 |
+
<head>
|
| 52 |
+
<meta charset="utf-8">
|
| 53 |
+
<title>Enterprise Contract Guardian β OpenEnv</title>
|
| 54 |
+
<meta name="viewport" content="width=device-width,initial-scale=1">
|
| 55 |
+
<style>
|
| 56 |
+
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
|
| 57 |
+
margin: 0; padding: 2rem; background: #0b1020; color: #e7ecf3; line-height: 1.55; }
|
| 58 |
+
.container { max-width: 760px; margin: 0 auto; }
|
| 59 |
+
h1 { font-size: 1.6rem; margin: 0 0 .25rem; }
|
| 60 |
+
h2 { font-size: 1.05rem; margin: 1.6rem 0 .5rem; color: #9bb0d6;
|
| 61 |
+
text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
|
| 62 |
+
.tag { display: inline-block; padding: 2px 10px; border-radius: 999px;
|
| 63 |
+
background: #16a34a; color: white; font-size: 0.78rem; font-weight: 600;
|
| 64 |
+
margin-left: .4rem; vertical-align: middle; }
|
| 65 |
+
a { color: #6db9ff; text-decoration: none; }
|
| 66 |
+
a:hover { text-decoration: underline; }
|
| 67 |
+
code { background: #1c2540; padding: 2px 6px; border-radius: 4px; font-size: .9em; }
|
| 68 |
+
pre { background: #1c2540; padding: 1rem; border-radius: 8px; overflow-x: auto; font-size: .88em; }
|
| 69 |
+
table { width: 100%; border-collapse: collapse; margin-top: .5rem; }
|
| 70 |
+
td, th { padding: .55rem .75rem; text-align: left;
|
| 71 |
+
border-bottom: 1px solid #1c2540; font-size: .92em; vertical-align: top; }
|
| 72 |
+
th { color: #9bb0d6; font-weight: 600; font-size: .78em;
|
| 73 |
+
text-transform: uppercase; letter-spacing: .04em; }
|
| 74 |
+
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
|
| 75 |
+
.card { background: #131a35; padding: 1rem 1.2rem; border-radius: 8px;
|
| 76 |
+
border: 1px solid #1c2540; }
|
| 77 |
+
.footer { margin-top: 2rem; color: #7c8db0; font-size: .82em; }
|
| 78 |
+
.pill { display:inline-block; padding:1px 8px; border-radius:6px;
|
| 79 |
+
background:#1c2540; font-size:.78em; color:#9bb0d6; margin-right:4px; }
|
| 80 |
+
</style>
|
| 81 |
+
</head>
|
| 82 |
+
<body>
|
| 83 |
+
<div class="container">
|
| 84 |
+
<h1>Enterprise Contract Guardian <span class="tag">RUNNING</span></h1>
|
| 85 |
+
<p>An <b>OpenEnv</b> RL environment that trains agents to detect API contract
|
| 86 |
+
violations, trace downstream blast radius across microservices, and propose
|
| 87 |
+
backward-compatible fixes.</p>
|
| 88 |
+
<p style="color:#9bb0d6;">
|
| 89 |
+
<span class="pill">Theme #3.1</span>
|
| 90 |
+
<span class="pill">Scaler AI Labs Bonus</span>
|
| 91 |
+
<span class="pill">openenv-core 0.2.3</span>
|
| 92 |
+
<span class="pill">9 tasks Β· 3 phases Β· 14 reward signals</span>
|
| 93 |
+
</p>
|
| 94 |
+
|
| 95 |
+
<h2>Endpoints</h2>
|
| 96 |
+
<table>
|
| 97 |
+
<tr><th>Method</th><th>Path</th><th>Purpose</th></tr>
|
| 98 |
+
<tr><td>GET</td><td><a href="/health">/health</a></td><td>Liveness check</td></tr>
|
| 99 |
+
<tr><td>GET</td><td><a href="/docs">/docs</a></td>
|
| 100 |
+
<td>Interactive Swagger UI — click "Try it out" on any endpoint</td></tr>
|
| 101 |
+
<tr><td>POST</td><td><code>/reset</code></td>
|
| 102 |
+
<td>Start a new episode (optional <code>task_name</code>, <code>seed</code>)</td></tr>
|
| 103 |
+
<tr><td>POST</td><td><code>/step</code></td>
|
| 104 |
+
<td>Submit one ValidatorAction</td></tr>
|
| 105 |
+
<tr><td>GET</td><td><code>/state</code></td>
|
| 106 |
+
<td>Current environment state</td></tr>
|
| 107 |
+
<tr><td>WS</td><td><code>/ws</code></td>
|
| 108 |
+
<td>WebSocket session</td></tr>
|
| 109 |
+
</table>
|
| 110 |
+
|
| 111 |
+
<h2>Try it from your terminal</h2>
|
| 112 |
+
<pre>HOST=https://pushpam14-api-contract-validator.hf.space
|
| 113 |
+
|
| 114 |
+
curl $HOST/health
|
| 115 |
+
# {"status":"healthy"}
|
| 116 |
+
|
| 117 |
+
curl -X POST $HOST/reset -H "Content-Type: application/json" \\
|
| 118 |
+
-d '{"task_name":"trace_downstream_blast_radius","seed":1}'</pre>
|
| 119 |
+
|
| 120 |
+
<h2>Tasks</h2>
|
| 121 |
+
<div class="grid">
|
| 122 |
+
<div class="card"><b>Phase 1 — Detection</b><br>
|
| 123 |
+
<code>find_type_mismatches</code><br>
|
| 124 |
+
<code>validate_nested_objects</code><br>
|
| 125 |
+
<code>detect_breaking_changes</code><br>
|
| 126 |
+
<code>validate_response_schema</code><br>
|
| 127 |
+
<code>validate_cross_field_constraints</code><br>
|
| 128 |
+
<code>validate_auth_request</code></div>
|
| 129 |
+
<div class="card"><b>Phase 2 — Impact Tracing</b><br>
|
| 130 |
+
<code>trace_downstream_blast_radius</code><br><br>
|
| 131 |
+
<b>Phase 3 — Fix & Verify</b><br>
|
| 132 |
+
<code>propose_backward_compat_fix</code><br>
|
| 133 |
+
<code>multi_service_cascade_fix</code></div>
|
| 134 |
+
</div>
|
| 135 |
+
|
| 136 |
+
<h2>Source & documentation</h2>
|
| 137 |
+
<p>
|
| 138 |
+
<a href="https://github.com/kumarpushpam17-personal/Hackathon">GitHub repo</a>
|
| 139 |
+
Β·
|
| 140 |
+
<a href="/docs">Swagger UI (interactive)</a>
|
| 141 |
+
Β·
|
| 142 |
+
<a href="/redoc">ReDoc API spec</a>
|
| 143 |
+
</p>
|
| 144 |
+
|
| 145 |
+
<p class="footer">Built with <code>openenv-core</code>, FastAPI, and the
|
| 146 |
+
OpenEnv <i>composable rubric</i> pattern. Reward signal stays independent
|
| 147 |
+
per phase, so per-component contributions are visible in training logs.</p>
|
| 148 |
+
</div>
|
| 149 |
+
</body>
|
| 150 |
+
</html>
|
| 151 |
+
"""
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
@app.get("/", response_class=HTMLResponse, include_in_schema=False)
|
| 155 |
+
async def root() -> HTMLResponse:
|
| 156 |
+
"""Landing page β what the HF Space iframe shows by default."""
|
| 157 |
+
return HTMLResponse(content=_LANDING_HTML)
|
| 158 |
+
|
| 159 |
+
|
| 160 |
def main(host: str = "0.0.0.0", port: int = 7860) -> None:
|
| 161 |
"""Entry point for ``uv run server`` or direct execution."""
|
| 162 |
import uvicorn
|