mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-03 11:55:00 +00:00
Add error handling and database insertion for YOLO results
This commit is contained in:
@@ -163,6 +163,18 @@ def yolo_results_endpoint():
|
|||||||
global yolo_results
|
global yolo_results
|
||||||
with lock:
|
with lock:
|
||||||
return jsonify(yolo_results)
|
return jsonify(yolo_results)
|
||||||
|
try:
|
||||||
|
data = json.loads(yolo_results)
|
||||||
|
db = get_db()
|
||||||
|
with db.cursor() as cursor:
|
||||||
|
sql_yolo = "INSERT INTO image (class, confidence) VALUES (%s, %s)"
|
||||||
|
cursor.executemany(sql_yolo, data)
|
||||||
|
db.commit()
|
||||||
|
cursor.close()
|
||||||
|
except json.JSONDecodeError as e:
|
||||||
|
print(f"JSON decode error: {e}")
|
||||||
|
except mysql.connector.Error as err:
|
||||||
|
print(f"Database error: {err}")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Reference in New Issue
Block a user