Add error handling and database insertion for YOLO results

This commit is contained in:
ishak jmilou.ishak
2025-01-14 13:23:48 +01:00
parent 2fbe18be76
commit ebd88e43ab

View File

@@ -163,6 +163,18 @@ def yolo_results_endpoint():
global yolo_results
with lock:
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__':