API improvements #4

Merged
s481871 merged 3 commits from flask-ML into dev 2024-01-18 23:34:16 +01:00
3 changed files with 3 additions and 3 deletions
Showing only changes of commit 294fb339ed - Show all commits

View File

@ -19,7 +19,7 @@ def translate(to_translate, lang):
for index, label_info in to_translate.items(): for index, label_info in to_translate.items():
label = label_info.get("label") label = label_info.get("label")
to_translate[index]["label"] = config.get(label).data to_translate[index]["label"] = config.get(label).data
return to_translate, None return to_translate, []
except Exception as e: except Exception as e:
error_message = f"Error translating labels: {e}" error_message = f"Error translating labels: {e}"
print(error_message) print(error_message)

View File

@ -95,7 +95,7 @@ def upload_file():
'isCat': False if not predictions else True, 'isCat': False if not predictions else True,
**({'predictions': predictions} if predictions is not None else {}) **({'predictions': predictions} if predictions is not None else {})
} }
if error_messages is not None and predictions is None: if len(error_messages) > 1:
results['errors'].append(error_messages) results['errors'].append(error_messages)
# Send response with 200 (Success) # Send response with 200 (Success)

View File

@ -25,7 +25,7 @@ def validate(request):
# Case 3 -> if some of the images has wrong extension # Case 3 -> if some of the images has wrong extension
for img in images: for img in images:
if imghdr.what(img) not in allowed_extensions: if not img.filename.lower().endswith(('.png', '.jpg', '.jpeg')):
raise ValueError(f"Given file '{img.filename}' has no allowed extension. " raise ValueError(f"Given file '{img.filename}' has no allowed extension. "
f"Allowed extensions: {allowed_extensions}.") f"Allowed extensions: {allowed_extensions}.")
except Exception as e: except Exception as e: