Spaces:
Sleeping
Sleeping
Update server/app.py
#13
by jithubaiju - opened
- server/app.py +8 -22
server/app.py
CHANGED
|
@@ -5,39 +5,26 @@ server/app.py - FastAPI server for the SQL Repair Environment.
|
|
| 5 |
import os
|
| 6 |
import sys
|
| 7 |
|
| 8 |
-
# Fix imports for both local and Docker environments
|
| 9 |
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 10 |
sys.path.insert(0, ROOT)
|
| 11 |
sys.path.insert(0, os.path.join(ROOT, "server"))
|
| 12 |
|
| 13 |
-
from fastapi.responses import JSONResponse
|
| 14 |
from openenv.core.env_server import create_fastapi_app
|
| 15 |
-
|
| 16 |
-
# Import models and environment using absolute paths
|
| 17 |
from models import SQLAction, SQLObservation
|
| 18 |
from server.environment import SQLRepairEnvironment, TASKS
|
| 19 |
|
| 20 |
-
|
| 21 |
app = create_fastapi_app(SQLRepairEnvironment, SQLAction, SQLObservation)
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
-
@app.get("/")
|
| 25 |
def root():
|
| 26 |
-
return
|
| 27 |
-
"name": "SQL Repair Environment",
|
| 28 |
-
"version": "1.0.0",
|
| 29 |
-
"status": "running",
|
| 30 |
-
"endpoints": {
|
| 31 |
-
"health": "/health",
|
| 32 |
-
"docs": "/docs",
|
| 33 |
-
"tasks": "/tasks",
|
| 34 |
-
"grader": "/grader",
|
| 35 |
-
"baseline": "/baseline",
|
| 36 |
-
"reset": "/reset",
|
| 37 |
-
"step": "/step",
|
| 38 |
-
"state": "/state",
|
| 39 |
-
}
|
| 40 |
-
})
|
| 41 |
|
| 42 |
|
| 43 |
@app.get("/tasks", tags=["Competition"])
|
|
@@ -77,7 +64,6 @@ def run_baseline():
|
|
| 77 |
|
| 78 |
|
| 79 |
def main():
|
| 80 |
-
"""Entry point for uv run server and project.scripts."""
|
| 81 |
import uvicorn
|
| 82 |
port = int(os.environ.get("PORT", 7860))
|
| 83 |
host = os.environ.get("HOST", "0.0.0.0")
|
|
|
|
| 5 |
import os
|
| 6 |
import sys
|
| 7 |
|
|
|
|
| 8 |
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 9 |
sys.path.insert(0, ROOT)
|
| 10 |
sys.path.insert(0, os.path.join(ROOT, "server"))
|
| 11 |
|
| 12 |
+
from fastapi.responses import JSONResponse, HTMLResponse
|
| 13 |
from openenv.core.env_server import create_fastapi_app
|
|
|
|
|
|
|
| 14 |
from models import SQLAction, SQLObservation
|
| 15 |
from server.environment import SQLRepairEnvironment, TASKS
|
| 16 |
|
|
|
|
| 17 |
app = create_fastapi_app(SQLRepairEnvironment, SQLAction, SQLObservation)
|
| 18 |
|
| 19 |
+
# ── read the UI HTML once at startup ─────────────────────────────────────────
|
| 20 |
+
_UI_PATH = os.path.join(ROOT, "ui.html")
|
| 21 |
+
with open(_UI_PATH, "r") as f:
|
| 22 |
+
_UI_HTML = f.read()
|
| 23 |
+
|
| 24 |
|
| 25 |
+
@app.get("/", response_class=HTMLResponse)
|
| 26 |
def root():
|
| 27 |
+
return HTMLResponse(content=_UI_HTML)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
|
| 30 |
@app.get("/tasks", tags=["Competition"])
|
|
|
|
| 64 |
|
| 65 |
|
| 66 |
def main():
|
|
|
|
| 67 |
import uvicorn
|
| 68 |
port = int(os.environ.get("PORT", 7860))
|
| 69 |
host = os.environ.get("HOST", "0.0.0.0")
|