Spaces:
Running
Running
fea:Adding API key filtering on Predict endpoint
Browse files
app.py
CHANGED
|
@@ -265,13 +265,13 @@ def warm_up_models():
|
|
| 265 |
with app.app_context():
|
| 266 |
warm_up_models()
|
| 267 |
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
|
| 276 |
@app.route('/predict', methods=['POST'])
|
| 277 |
def predict():
|
|
|
|
| 265 |
with app.app_context():
|
| 266 |
warm_up_models()
|
| 267 |
|
| 268 |
+
@app.before_request
|
| 269 |
+
def check_rapidapi_key():
|
| 270 |
+
"""Verify RapidAPI key for security"""
|
| 271 |
+
if request.path == '/predict':
|
| 272 |
+
rapidapi_key = request.headers.get('X-RapidAPI-Key')
|
| 273 |
+
if not rapidapi_key:
|
| 274 |
+
return jsonify({'error': 'Missing X-RapidAPI-Key header'}), 401
|
| 275 |
|
| 276 |
@app.route('/predict', methods=['POST'])
|
| 277 |
def predict():
|