Spaces:
Running
Running
Add seperate status.py router
Browse files
status.py
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# status.py
|
| 2 |
+
from fastapi import APIRouter, Response
|
| 3 |
+
from fastapi.responses import JSONResponse
|
| 4 |
+
|
| 5 |
+
router = APIRouter(prefix="/status")
|
| 6 |
+
|
| 7 |
+
@router.head("/sfx")
|
| 8 |
+
async def head_sfx():
|
| 9 |
+
return Response(
|
| 10 |
+
status_code=200,
|
| 11 |
+
headers={
|
| 12 |
+
"Content-Type": "audio/mpeg",
|
| 13 |
+
"Accept-Ranges": "bytes",
|
| 14 |
+
},
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
@router.head("/image")
|
| 18 |
+
async def head_image():
|
| 19 |
+
return Response(
|
| 20 |
+
status_code=200,
|
| 21 |
+
headers={
|
| 22 |
+
"Content-Type": "image/jpeg",
|
| 23 |
+
"Accept-Ranges": "bytes",
|
| 24 |
+
},
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
@router.head("/video")
|
| 28 |
+
async def head_video():
|
| 29 |
+
return Response(
|
| 30 |
+
status_code=200,
|
| 31 |
+
headers={
|
| 32 |
+
"Content-Type": "video/mp4",
|
| 33 |
+
"Accept-Ranges": "bytes",
|
| 34 |
+
},
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
@router.head("/text")
|
| 38 |
+
async def head_text():
|
| 39 |
+
return Response(
|
| 40 |
+
status_code=200,
|
| 41 |
+
headers={
|
| 42 |
+
"Content-Type": "application/json",
|
| 43 |
+
"Accept-Ranges": "bytes",
|
| 44 |
+
},
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
@router.get("/")
|
| 48 |
+
async def get_status():
|
| 49 |
+
notify = ""
|
| 50 |
+
services = {
|
| 51 |
+
"Video Generation": {"code": 200, "state": "ok", "message": "Running Normally"},
|
| 52 |
+
"Image Generation": {"code": 200, "state": "ok", "message": "Running Normally"},
|
| 53 |
+
"Lightning-Text v2": {"code": 200, "state": "ok", "message": "Running normally"},
|
| 54 |
+
"Music/SFX Generation": {"code": 200, "state": "ok", "message": "Running normally"},
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
overall_state = (
|
| 58 |
+
"ok" if all(s["state"] == "ok" for s in services.values()) else "degraded"
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
return JSONResponse(
|
| 62 |
+
status_code=200,
|
| 63 |
+
content={
|
| 64 |
+
"state": overall_state,
|
| 65 |
+
"services": services,
|
| 66 |
+
"notifications": notify,
|
| 67 |
+
"latest": "2.9.1",
|
| 68 |
+
},
|
| 69 |
+
)
|