Spaces:
Sleeping
Sleeping
saifisvibinn commited on
Commit ·
f96bca8
1
Parent(s): b10e99d
Add GET handler to /api/predict for better error messages
Browse files
app.py
CHANGED
|
@@ -89,8 +89,22 @@ def api_docs():
|
|
| 89 |
return render_template('api_docs.html', routes=routes, base_url=base_url)
|
| 90 |
|
| 91 |
|
| 92 |
-
@app.route('/api/predict', methods=['POST'])
|
| 93 |
def predict():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
"""
|
| 95 |
Clean REST API endpoint for PDF extraction.
|
| 96 |
Accepts a PDF file and returns extracted text, tables, and figures.
|
|
|
|
| 89 |
return render_template('api_docs.html', routes=routes, base_url=base_url)
|
| 90 |
|
| 91 |
|
| 92 |
+
@app.route('/api/predict', methods=['POST', 'GET'])
|
| 93 |
def predict():
|
| 94 |
+
# Handle GET requests with info message
|
| 95 |
+
if request.method == 'GET':
|
| 96 |
+
return jsonify({
|
| 97 |
+
'status': 'info',
|
| 98 |
+
'message': 'This endpoint accepts POST requests only. Please use POST method with a PDF file in the "file" field.',
|
| 99 |
+
'usage': {
|
| 100 |
+
'method': 'POST',
|
| 101 |
+
'content_type': 'multipart/form-data',
|
| 102 |
+
'body': {
|
| 103 |
+
'file': 'PDF file to process'
|
| 104 |
+
},
|
| 105 |
+
'example_curl': 'curl -X POST https://saifisvibin-volaris-pdf-tool.hf.space/api/predict -F "file=@document.pdf"'
|
| 106 |
+
}
|
| 107 |
+
}), 405
|
| 108 |
"""
|
| 109 |
Clean REST API endpoint for PDF extraction.
|
| 110 |
Accepts a PDF file and returns extracted text, tables, and figures.
|