Spaces:
Running
Running
zeeshan
commited on
Commit
·
33b30a2
1
Parent(s):
13f9521
Fix root endpoint to serve HTML instead of JSON
Browse files- deployment/backend/backend.py +21 -14
deployment/backend/backend.py
CHANGED
|
@@ -21,6 +21,7 @@ import cv2
|
|
| 21 |
from fastapi import FastAPI, File, UploadFile, HTTPException
|
| 22 |
from fastapi.middleware.cors import CORSMiddleware
|
| 23 |
from fastapi.staticfiles import StaticFiles
|
|
|
|
| 24 |
from pydantic import BaseModel
|
| 25 |
import uvicorn
|
| 26 |
|
|
@@ -90,22 +91,28 @@ app.add_middleware(
|
|
| 90 |
# Root endpoint
|
| 91 |
# ============================================================================
|
| 92 |
|
| 93 |
-
@app.get("/")
|
| 94 |
async def root():
|
| 95 |
"""Root endpoint - serve index.html"""
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
"
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
|
| 111 |
# ============================================================================
|
|
|
|
| 21 |
from fastapi import FastAPI, File, UploadFile, HTTPException
|
| 22 |
from fastapi.middleware.cors import CORSMiddleware
|
| 23 |
from fastapi.staticfiles import StaticFiles
|
| 24 |
+
from fastapi.responses import FileResponse, HTMLResponse
|
| 25 |
from pydantic import BaseModel
|
| 26 |
import uvicorn
|
| 27 |
|
|
|
|
| 91 |
# Root endpoint
|
| 92 |
# ============================================================================
|
| 93 |
|
| 94 |
+
@app.get("/", response_class=HTMLResponse)
|
| 95 |
async def root():
|
| 96 |
"""Root endpoint - serve index.html"""
|
| 97 |
+
index_path = Config.FRONTEND_DIR / "index.html"
|
| 98 |
+
if index_path.exists():
|
| 99 |
+
with open(index_path, "r") as f:
|
| 100 |
+
return f.read()
|
| 101 |
+
return """
|
| 102 |
+
<html>
|
| 103 |
+
<body style="font-family: monospace; margin: 20px;">
|
| 104 |
+
<h1>RoDLA Document Layout Analysis API</h1>
|
| 105 |
+
<p>API is running but frontend files not found.</p>
|
| 106 |
+
<h2>Available Endpoints:</h2>
|
| 107 |
+
<ul>
|
| 108 |
+
<li><a href="/api/health">GET /api/health</a> - Health check</li>
|
| 109 |
+
<li><a href="/api/model-info">GET /api/model-info</a> - Model info</li>
|
| 110 |
+
<li>POST /api/detect - Detection endpoint</li>
|
| 111 |
+
<li>POST /api/generate-perturbations - Perturbations</li>
|
| 112 |
+
</ul>
|
| 113 |
+
</body>
|
| 114 |
+
</html>
|
| 115 |
+
"""
|
| 116 |
|
| 117 |
|
| 118 |
# ============================================================================
|