Skip to content

Commit

Permalink
MET-5350 remove garbage colleciton
Browse files Browse the repository at this point in the history
  • Loading branch information
jeortizquan committed Aug 7, 2023
1 parent 086ba2c commit e645d70
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions metis-image-enhancer-python-rest/src/main/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import socket
import io
import filetype
import gc

from flask import Flask, request, jsonify, send_file, make_response
from waitress import serve
Expand Down Expand Up @@ -64,8 +63,9 @@ def enhance_image():
img = Image.open(io.BytesIO(image_data)).convert("RGBA")
rgb_img = Image.new("RGBA", img.size, "WHITE")
rgb_img.paste(img, mask=img)
sr_img = model.predict(np.array(rgb_img.convert("RGB")), by_patch_of_size=16)
sr_img = Image.fromarray(sr_img)

sr_mod = model.predict(np.array(rgb_img.convert("RGB")), by_patch_of_size=24)
sr_img = Image.fromarray(sr_mod)

# save it to memory in the original format
raw_bytes = io.BytesIO()
Expand All @@ -82,17 +82,19 @@ def enhance_image():

#response file with bytes and mime type
response = make_response(send_file(raw_bytes, mimetype=kind.mime))

# processing elapsed time
end_process = time.time()
response.headers['Elapsed-Time'] = end_process - start_process

del raw_bytes
del sr_mod
del sr_img
del rgb_img
del img
del image_data
gc.collect()
return response

return response, 200

if request.method == 'GET':
app.logger.info('GET request running on host: ' + socket.gethostname())
Expand Down

0 comments on commit e645d70

Please sign in to comment.