Spaces:
Sleeping
Sleeping
Allow any file key
Browse files
app.py
CHANGED
|
@@ -48,12 +48,15 @@ def serve_root_files(filename):
|
|
| 48 |
return "File not found", 404
|
| 49 |
|
| 50 |
# 4. Handle Predictions
|
|
|
|
| 51 |
@app.route('/api/classify', methods=['POST'])
|
| 52 |
def predict():
|
| 53 |
-
if
|
|
|
|
| 54 |
return jsonify({'error': 'No file uploaded'}), 400
|
| 55 |
|
| 56 |
-
file
|
|
|
|
| 57 |
|
| 58 |
try:
|
| 59 |
processed_img = prepare_image(file.read())
|
|
|
|
| 48 |
return "File not found", 404
|
| 49 |
|
| 50 |
# 4. Handle Predictions
|
| 51 |
+
# Updated Predict Function - Accepts ANY file name
|
| 52 |
@app.route('/api/classify', methods=['POST'])
|
| 53 |
def predict():
|
| 54 |
+
# Check if ANY file was uploaded
|
| 55 |
+
if not request.files:
|
| 56 |
return jsonify({'error': 'No file uploaded'}), 400
|
| 57 |
|
| 58 |
+
# Grab the first file found, regardless of its key name ('file', 'image', 'img', etc.)
|
| 59 |
+
file = next(iter(request.files.values()))
|
| 60 |
|
| 61 |
try:
|
| 62 |
processed_img = prepare_image(file.read())
|