1 Commits
Author SHA1 Message Date
Haitem 38e13d94dd Update file path 2025-06-30 15:20:19 +02:00
+6 -12
View File
@@ -10,8 +10,7 @@ from retinaface import RetinaFace
treashold = float(os.getenv('FACE_TRASHOLD', '0.9')) treashold = float(os.getenv('FACE_TRASHOLD', '0.9'))
sever = os.getenv('API_ROOT', 'localhost:8000') sever = os.getenv('API_ROOT', 'localhost:8000')
disk_treashold = float(os.getenv('DISK_FREE_TRASHOLD', '10.0')) disk_treashold = os.getenv('DISK_FREE_TRASHOLD', 10)
disk_treashold_gb = float(os.getenv('DISK_FREE_TRASHOLD_GB', '20.0'))
root_api_url = 'http://{}/local'.format(sever) root_api_url = 'http://{}/local'.format(sever)
base_path = '/app/data/' base_path = '/app/data/'
@@ -19,7 +18,6 @@ base_path = '/app/data/'
print("API_ROOT: " + str(root_api_url), flush=True) print("API_ROOT: " + str(root_api_url), flush=True)
print("FACE_TRASHOLD: " + str(treashold), flush=True) print("FACE_TRASHOLD: " + str(treashold), flush=True)
print("DISK_FREE_TRASHOLD: " + str(disk_treashold), flush=True) print("DISK_FREE_TRASHOLD: " + str(disk_treashold), flush=True)
print("DISK_FREE_TRASHOLD_GB: " + str(disk_treashold_gb), flush=True)
try: try:
while True: while True:
@@ -28,14 +26,10 @@ try:
#Chesk if there is enought free space at destination path #Chesk if there is enought free space at destination path
while True: while True:
total, used, free = shutil.disk_usage(base_path) total, used, free = shutil.disk_usage(base_path)
free_gb = free / (2**30) if (free // (2**30)) > ((total / 100) * disk_treashold) // (2**30):
below_percent = free < (total / 100) * disk_treashold
not_above_gb = free_gb <= disk_treashold_gb
# Not enough space only if free space is below the % threshold AND not above the GB threshold
if not (below_percent and not_above_gb):
break break
data = {"trace": "not enought free space at destination" + str(base_path) + " trashold is: " + str(disk_treashold) + "% and " + str(disk_treashold_gb) + " GB"} data = {"trace": "not enought free space at destination" + str(base_path) + " trashold is: " + str(disk_treashold) + "%"}
response = requests.post('{}/log'.format(root_api_url), json=data) response = requests.post('{}/log'.format(root_api_url), json=data)
print("sleep", flush=True) print("sleep", flush=True)
@@ -49,7 +43,7 @@ try:
for detection in response: for detection in response:
print(str(detection['id']) + " Anonymization Started", flush=True) print(str(detection['id']) + " Anonymization Started", flush=True)
img_path = "{}{}".format(base_path, detection['source_image_path']) img_path = "{}{}".format(base_path, detection['path'])
#print(img_path, flush=True) #print(img_path, flush=True)
#Skip Non existing files #Skip Non existing files
if (not os.path.exists(img_path)): if (not os.path.exists(img_path)):
@@ -63,7 +57,7 @@ try:
if (len(faces) <= 0): if (len(faces) <= 0):
data = { data = {
"id": detection['id'], "id": detection['id'],
"source_image_path": img_path.replace(base_path,""), "path": img_path.replace(base_path,""),
"face_found": 0, "face_found": 0,
} }
response = requests.post('{}/anonymize'.format(root_api_url), json=data) response = requests.post('{}/anonymize'.format(root_api_url), json=data)
@@ -99,7 +93,7 @@ try:
data = { data = {
"id": detection['id'], "id": detection['id'],
"source_image_path": new_img_path.replace(base_path,""), "path": new_img_path.replace(base_path,""),
"face_found": len(faces), "face_found": len(faces),
} }
response = requests.post('{}/anonymize'.format(root_api_url), json=data) response = requests.post('{}/anonymize'.format(root_api_url), json=data)