Spaces:
Sleeping
Sleeping
Add root endpoint with API info page
Browse files
main.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
| 1 |
# main.py
|
| 2 |
|
| 3 |
from fastapi import FastAPI, HTTPException, Request
|
| 4 |
-
from fastapi.responses import JSONResponse
|
| 5 |
import tensorflow as tf
|
| 6 |
import numpy as np
|
| 7 |
import base64
|
|
@@ -106,6 +106,58 @@ async def log_requests(request: Request, call_next):
|
|
| 106 |
)
|
| 107 |
return response
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
# =============================================================================
|
| 110 |
# HEALTH
|
| 111 |
# =============================================================================
|
|
|
|
| 1 |
# main.py
|
| 2 |
|
| 3 |
from fastapi import FastAPI, HTTPException, Request
|
| 4 |
+
from fastapi.responses import JSONResponse, HTMLResponse
|
| 5 |
import tensorflow as tf
|
| 6 |
import numpy as np
|
| 7 |
import base64
|
|
|
|
| 106 |
)
|
| 107 |
return response
|
| 108 |
|
| 109 |
+
# =============================================================================
|
| 110 |
+
# ROOT ENDPOINT
|
| 111 |
+
# =============================================================================
|
| 112 |
+
|
| 113 |
+
@app.get("/", response_class=HTMLResponse)
|
| 114 |
+
def root():
|
| 115 |
+
"""Serve a simple HTML page with API info."""
|
| 116 |
+
return """
|
| 117 |
+
<!DOCTYPE html>
|
| 118 |
+
<html>
|
| 119 |
+
<head>
|
| 120 |
+
<title>Forest Segmentation API</title>
|
| 121 |
+
<style>
|
| 122 |
+
body { font-family: Arial, sans-serif; margin: 40px; background-color: #f5f5f5; }
|
| 123 |
+
.container { background-color: white; padding: 20px; border-radius: 8px; max-width: 800px; }
|
| 124 |
+
h1 { color: #333; }
|
| 125 |
+
.endpoint { background-color: #f0f0f0; padding: 10px; margin: 10px 0; border-left: 4px solid #4CAF50; }
|
| 126 |
+
code { background-color: #f9f9f9; padding: 2px 6px; border-radius: 3px; }
|
| 127 |
+
.status { color: #4CAF50; font-weight: bold; }
|
| 128 |
+
</style>
|
| 129 |
+
</head>
|
| 130 |
+
<body>
|
| 131 |
+
<div class="container">
|
| 132 |
+
<h1>🌲 Forest Segmentation API</h1>
|
| 133 |
+
<p>Landsat 8 Forest Segmentation Model</p>
|
| 134 |
+
|
| 135 |
+
<h2>API Endpoints</h2>
|
| 136 |
+
<div class="endpoint">
|
| 137 |
+
<strong>Health Check</strong><br>
|
| 138 |
+
<code>GET /health</code><br>
|
| 139 |
+
Returns API status
|
| 140 |
+
</div>
|
| 141 |
+
|
| 142 |
+
<div class="endpoint">
|
| 143 |
+
<strong>Predict</strong><br>
|
| 144 |
+
<code>POST /predict</code><br>
|
| 145 |
+
Send Landsat bands for forest segmentation
|
| 146 |
+
</div>
|
| 147 |
+
|
| 148 |
+
<div class="endpoint">
|
| 149 |
+
<strong>API Docs</strong><br>
|
| 150 |
+
<code>GET /docs</code><br>
|
| 151 |
+
Interactive Swagger UI
|
| 152 |
+
</div>
|
| 153 |
+
|
| 154 |
+
<h2>Status</h2>
|
| 155 |
+
<p><span class="status">✓ API is running</span></p>
|
| 156 |
+
</div>
|
| 157 |
+
</body>
|
| 158 |
+
</html>
|
| 159 |
+
"""
|
| 160 |
+
|
| 161 |
# =============================================================================
|
| 162 |
# HEALTH
|
| 163 |
# =============================================================================
|