Spaces:
Sleeping
Sleeping
Download server/app.py from Akshayaitis/sql-debug-env: direct link, hf CLI and curl.
- Browser
- Download file 5.69 kB
-
https://huggingface.co/spaces/Akshayaitis/sql-debug-env/resolve/main/server/app.py
- Command line
-
hf download hf://spaces/Akshayaitis/sql-debug-env/server/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Akshayaitis/sql-debug-env/resolve/main/server/app.py
5.69 kB
| """ | |
| FastAPI server for the SQL Debug Environment. | |
| Hooks into openenv-core's create_fastapi_app() for the standard /ws endpoint, | |
| then slaps on a landing page and health check on top. Nothing fancy. | |
| """ | |
| from __future__ import annotations | |
| import logging | |
| from fastapi import FastAPI | |
| from fastapi.middleware.cors import CORSMiddleware | |
| from fastapi.responses import HTMLResponse | |
| from openenv.core.env_server import create_fastapi_app | |
| from server.environment import SQLDebugEnvironment | |
| from sql_debug_env.models import SQLAction, SQLObservation | |
| logger = logging.getLogger("sql-debug-env") | |
| logging.basicConfig(level=logging.INFO) | |
| # ββ Wire up the OpenEnv app ββββββββββββββββββββββββββββββββββββββββ | |
| app: FastAPI = create_fastapi_app( | |
| env=SQLDebugEnvironment, | |
| action_cls=SQLAction, | |
| observation_cls=SQLObservation, | |
| ) | |
| app.title = "SQL Debug Environment" | |
| app.description = ( | |
| "OpenEnv-compatible environment for SQL debugging and optimization. " | |
| "Agents fix broken queries through iterative execution feedback." | |
| ) | |
| app.version = "1.0.0" | |
| app.contact = {"name": "SQL Debug Env Team"} | |
| app.license_info = {"name": "MIT", "url": "https://opensource.org/licenses/MIT"} | |
| # Wide open CORS β this is a dev/hackathon tool, not a bank | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_credentials=True, | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| # ββ Landing page ββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| # | |
| # Just a quick info card so you know it's alive when you hit the root URL. | |
| # Nothing too wild β dark theme, lists the tasks, links to the docs. | |
| LANDING_HTML = """ | |
| <!DOCTYPE html> | |
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>SQL Debug Environment</title> | |
| <style> | |
| *{margin:0;padding:0;box-sizing:border-box} | |
| body{font-family:'Segoe UI',system-ui,-apple-system,sans-serif; | |
| background:#0f172a;color:#e2e8f0;min-height:100vh; | |
| display:flex;align-items:center;justify-content:center} | |
| .card{background:#1e293b;border-radius:16px;padding:48px; | |
| max-width:720px;width:90%;box-shadow:0 25px 50px rgba(0,0,0,.4)} | |
| h1{font-size:2rem;margin-bottom:8px; | |
| background:linear-gradient(135deg,#38bdf8,#818cf8); | |
| -webkit-background-clip:text;-webkit-text-fill-color:transparent} | |
| .subtitle{color:#94a3b8;margin-bottom:32px;font-size:1.05rem} | |
| .tasks{display:grid;gap:12px;margin-bottom:32px} | |
| .task{background:#334155;border-radius:10px;padding:16px 20px; | |
| display:flex;align-items:center;gap:14px; | |
| transition:transform .15s} | |
| .task:hover{transform:translateX(4px)} | |
| .badge{padding:4px 10px;border-radius:6px;font-size:.75rem; | |
| font-weight:700;text-transform:uppercase;flex-shrink:0} | |
| .easy{background:#166534;color:#4ade80} | |
| .medium{background:#854d0e;color:#facc15} | |
| .hard{background:#991b1b;color:#f87171} | |
| .task-name{font-weight:600} | |
| .task-id{color:#64748b;font-size:.85rem;font-family:monospace} | |
| .endpoints{margin-bottom:28px} | |
| .endpoints h2{font-size:1rem;color:#94a3b8;margin-bottom:12px} | |
| .ep{font-family:monospace;font-size:.9rem;padding:6px 0; | |
| display:flex;gap:10px;align-items:center} | |
| .method{padding:2px 8px;border-radius:4px;font-weight:700;font-size:.75rem} | |
| .post{background:#1d4ed8;color:#bfdbfe} | |
| .get{background:#15803d;color:#bbf7d0} | |
| .ws{background:#7e22ce;color:#e9d5ff} | |
| a{color:#38bdf8;text-decoration:none} | |
| a:hover{text-decoration:underline} | |
| .footer{color:#475569;font-size:.85rem;margin-top:24px; | |
| padding-top:20px;border-top:1px solid #334155} | |
| </style> | |
| </head> | |
| <body> | |
| <div class="card"> | |
| <h1>π οΈ SQL Debug Environment</h1> | |
| <p class="subtitle">Interactive SQL debugging & optimization β powered by OpenEnv</p> | |
| <div class="tasks"> | |
| <div class="task"> | |
| <span class="badge easy">Easy</span> | |
| <div><span class="task-name">Fix SQL Syntax Errors</span><br> | |
| <span class="task-id">fix_syntax</span></div> | |
| </div> | |
| <div class="task"> | |
| <span class="badge medium">Medium</span> | |
| <div><span class="task-name">Fix Wrong JOIN Logic</span><br> | |
| <span class="task-id">fix_join</span></div> | |
| </div> | |
| <div class="task"> | |
| <span class="badge hard">Hard</span> | |
| <div><span class="task-name">Optimize Correlated Subquery</span><br> | |
| <span class="task-id">optimize_query</span></div> | |
| </div> | |
| </div> | |
| <div class="endpoints"> | |
| <h2>Endpoints</h2> | |
| <div class="ep"><span class="method ws">WS</span> <span>/ws</span> β Main interaction (reset / step / state)</div> | |
| <div class="ep"><span class="method get">GET</span> <span>/health</span> β Health check</div> | |
| </div> | |
| <p>π <a href="/docs">Swagger Docs</a> | | |
| π <a href="/redoc">ReDoc</a></p> | |
| <div class="footer"> | |
| Built with OpenEnv Β· FastAPI Β· SQLite | |
| </div> | |
| </div> | |
| </body> | |
| </html> | |
| """ | |
| async def root(): | |
| """Serve the landing page.""" | |
| return LANDING_HTML | |
| async def health(): | |
| """Quick health check β just confirms the server is up.""" | |
| return {"status": "ok", "environment": "sql-debug-env"} | |
| # ββ Entry point βββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| def main(): | |
| import uvicorn | |
| uvicorn.run(app, host="0.0.0.0", port=7860) | |
| if __name__ == "__main__": | |
| main() | |