Abhishek Tiwari commited on
Commit
137f02a
Β·
1 Parent(s): 6d2ec98

fix: smart redirect to /web for browsers to fix HF UI, keep JSON for APIs

Browse files
Files changed (1) hide show
  1. server/app.py +9 -3
server/app.py CHANGED
@@ -1,5 +1,5 @@
1
- from fastapi import FastAPI, WebSocket, WebSocketDisconnect
2
- from fastapi.responses import HTMLResponse
3
  from pydantic import BaseModel
4
  from typing import Optional
5
  import json
@@ -32,7 +32,13 @@ class GradeRequest(BaseModel):
32
  # ── HTTP endpoints ────────────────────────────────────────────────────────────
33
 
34
  @app.get("/")
35
- def root():
 
 
 
 
 
 
36
  return {
37
  "info": "SQL Agent Environment API",
38
  "version": "1.0.0",
 
1
+ from fastapi import FastAPI, WebSocket, WebSocketDisconnect, Request
2
+ from fastapi.responses import HTMLResponse, RedirectResponse
3
  from pydantic import BaseModel
4
  from typing import Optional
5
  import json
 
32
  # ── HTTP endpoints ────────────────────────────────────────────────────────────
33
 
34
  @app.get("/")
35
+ def root(request: Request):
36
+ # Smart routing: If a human browser loads the root URL, direct them to the UI!
37
+ # If the Hackathon Validator automated bot calls the root URL, serve the required JSON.
38
+ accept = request.headers.get("accept", "")
39
+ if "text/html" in accept:
40
+ return RedirectResponse(url="/web")
41
+
42
  return {
43
  "info": "SQL Agent Environment API",
44
  "version": "1.0.0",