Add simple logging

This commit is contained in:
niten 2023-01-07 17:19:06 -08:00
parent a5b9ee4cd7
commit 22414a4378
1 changed files with 5 additions and 0 deletions

View File

@ -91,16 +91,21 @@ def result_to_dict(res, base_url):
@app.put("/images/")
async def analyze_image(file: UploadFile, request: Request):
print("Initiating file receipt, url: " + str(request.url))
base_url = re.sub(r'\/images\/$', '/analyzed_images/', str(request.url))
infile = open(incoming_dir / file.filename)
file_hash = hashlib.sha256()
with open(infile, mode="wb") as f:
chunk = f.read(buffer_size)
while chunk:
print("writing chunk")
file_hash.update(chunk)
infile.write(chunk)
chunk=f.read(buffer_size)
print("saving complete")
print("analyzing image")
result = detector.detect_objects(infile, file_hash.hexdigest() + ".png")
print("image analyzed")
remove(infile)
return result_to_dict(result, base_url)