Add /api/health endpoint for service monitoring and health checks
Browse files
app.py
CHANGED
|
@@ -401,6 +401,8 @@ with gr.Blocks(title="Industrial Defect Detection") as demo:
|
|
| 401 |
with gr.Row(visible=False):
|
| 402 |
models_btn = gr.Button("Get Models")
|
| 403 |
models_output = gr.JSON()
|
|
|
|
|
|
|
| 404 |
|
| 405 |
def get_models():
|
| 406 |
"""Return list of available models."""
|
|
@@ -409,6 +411,16 @@ with gr.Blocks(title="Industrial Defect Detection") as demo:
|
|
| 409 |
"count": len(MODELS)
|
| 410 |
}
|
| 411 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 412 |
models_btn.click(
|
| 413 |
fn=get_models,
|
| 414 |
inputs=[],
|
|
@@ -416,6 +428,13 @@ with gr.Blocks(title="Industrial Defect Detection") as demo:
|
|
| 416 |
api_name="models" # Creates /api/models endpoint
|
| 417 |
)
|
| 418 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 419 |
# Launch the app
|
| 420 |
if __name__ == "__main__":
|
| 421 |
demo.launch()
|
|
|
|
| 401 |
with gr.Row(visible=False):
|
| 402 |
models_btn = gr.Button("Get Models")
|
| 403 |
models_output = gr.JSON()
|
| 404 |
+
health_btn = gr.Button("Health Check")
|
| 405 |
+
health_output = gr.JSON()
|
| 406 |
|
| 407 |
def get_models():
|
| 408 |
"""Return list of available models."""
|
|
|
|
| 411 |
"count": len(MODELS)
|
| 412 |
}
|
| 413 |
|
| 414 |
+
def health_check():
|
| 415 |
+
"""Health check endpoint for monitoring."""
|
| 416 |
+
return {
|
| 417 |
+
"status": "healthy",
|
| 418 |
+
"service": "Gradio Inference (HuggingFace)",
|
| 419 |
+
"models_loaded": len(sessions),
|
| 420 |
+
"available_models": len(MODELS),
|
| 421 |
+
"timestamp": datetime.now().isoformat()
|
| 422 |
+
}
|
| 423 |
+
|
| 424 |
models_btn.click(
|
| 425 |
fn=get_models,
|
| 426 |
inputs=[],
|
|
|
|
| 428 |
api_name="models" # Creates /api/models endpoint
|
| 429 |
)
|
| 430 |
|
| 431 |
+
health_btn.click(
|
| 432 |
+
fn=health_check,
|
| 433 |
+
inputs=[],
|
| 434 |
+
outputs=health_output,
|
| 435 |
+
api_name="health" # Creates /api/health endpoint
|
| 436 |
+
)
|
| 437 |
+
|
| 438 |
# Launch the app
|
| 439 |
if __name__ == "__main__":
|
| 440 |
demo.launch()
|