Priyansh Saxena commited on
Commit
ea534aa
·
1 Parent(s): cb6c215

Add health endpoint and cold-start wake guidance

Browse files
Files changed (2) hide show
  1. README.md +29 -0
  2. app.py +13 -1
README.md CHANGED
@@ -49,6 +49,35 @@ Built with:
49
 
50
  Deploy to Hugging Face Spaces with Docker support enabled.
51
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  ---
53
 
54
  For more information, visit the [project repository](https://github.com/priyansh-saxena1/LLM-Integrated-Excel-Plotter-App)
 
49
 
50
  Deploy to Hugging Face Spaces with Docker support enabled.
51
 
52
+ ## Health And Wake-Up Endpoint
53
+
54
+ To support cold-start recovery on free-tier Hugging Face Spaces, this backend exposes:
55
+
56
+ - `GET /health`
57
+
58
+ This endpoint is lightweight and intended for:
59
+
60
+ - frontend wake-up checks before user requests,
61
+ - retry logic diagnostics,
62
+ - optional cron-based warm-up pings.
63
+
64
+ Example:
65
+
66
+ ```bash
67
+ curl https://<your-space>.hf.space/health
68
+ ```
69
+
70
+ Typical response:
71
+
72
+ ```json
73
+ {
74
+ "status": "ok",
75
+ "service": "llm-excel-plotter-agent",
76
+ "uptime_seconds": 12.34,
77
+ "timestamp": 1700000000
78
+ }
79
+ ```
80
+
81
  ---
82
 
83
  For more information, visit the [project repository](https://github.com/priyansh-saxena1/LLM-Integrated-Excel-Plotter-App)
app.py CHANGED
@@ -35,6 +35,7 @@ app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER
35
  app.config['MAX_CONTENT_LENGTH'] = MAX_UPLOAD_BYTES
36
 
37
  os.makedirs(UPLOAD_FOLDER, exist_ok=True)
 
38
 
39
 
40
  def allowed_file(filename):
@@ -46,7 +47,18 @@ def index():
46
  return jsonify({
47
  "status": "ok",
48
  "message": "AI Data Visualization API",
49
- "endpoints": ["/plot", "/upload", "/stats", "/models"]
 
 
 
 
 
 
 
 
 
 
 
50
  })
51
 
52
 
 
35
  app.config['MAX_CONTENT_LENGTH'] = MAX_UPLOAD_BYTES
36
 
37
  os.makedirs(UPLOAD_FOLDER, exist_ok=True)
38
+ STARTED_AT = time.time()
39
 
40
 
41
  def allowed_file(filename):
 
47
  return jsonify({
48
  "status": "ok",
49
  "message": "AI Data Visualization API",
50
+ "endpoints": ["/health", "/plot", "/upload", "/stats", "/models"]
51
+ })
52
+
53
+
54
+ @app.route('/health', methods=['GET'])
55
+ def health():
56
+ """Lightweight endpoint used by frontend wake-up checks and cron pings."""
57
+ return jsonify({
58
+ "status": "ok",
59
+ "service": "llm-excel-plotter-agent",
60
+ "uptime_seconds": round(time.time() - STARTED_AT, 2),
61
+ "timestamp": int(time.time()),
62
  })
63
 
64