Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
output = []
for index, each in enumerate(csv_dict):
each.update(results[index])
output.append(each)
if not os.path.isdir(target_folder):
os.makedirs(target_folder)
file_identifier = str(uuid.uuid4())
output_file_path = os.path.join(target_folder,
file_identifier + ".csv")
head = output[0].keys()
with open(output_file_path, 'w') as file_obj:
writer = DictWriter(file_obj, fieldnames=head)
writer.writeheader()
for each in output:
writer.writerow(each)
return json_resp({'filename': file_identifier + ".csv"}, status=200)
except Exception as e:
traceback.print_exc()
return json_resp({"error": str(e), "code": "500"}, status=500)
# make sure the UPLOAD_FOLDER exsits
if not os.path.isdir(upload_folder):
os.makedirs(upload_folder)
file_abs_path = os.path.join(upload_folder, filename)
uploaded_file.save(file_abs_path)
data['input_file_path'] = file_abs_path
try:
if request_type == "infer":
results = aidserver.solver.infer(data)
else:
raise NotImplementedError
if 'delete_after_process' in data:
if str2bool(data['delete_after_process']):
os.remove(file_abs_path)
print(results)
return json_resp(results, status=200)
except Exception as e:
traceback.print_exc()
return json_resp({"error": str(e), "code": "500"}, status=500)
async def ping():
return await json_resp({"status": "OK"}, status=200)