Skip to content

Commit

Permalink
fix(api): typesafe param hashing
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Jan 8, 2023
1 parent e82379c commit f4ca6a0
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion api/onnx_web/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from io import BytesIO
from PIL import Image
from stringcase import spinalcase
from struct import pack
from os import environ, makedirs, path, scandir
import numpy as np

Expand Down Expand Up @@ -144,7 +145,14 @@ def make_output_path(type, params):
sha = sha256()
sha.update(type)
for param in params:
sha.update(param)
if isinstance(param, str):
sha.update(param.encode('utf-8'))
elif isinstance(param, int):
sha.update(bytearray(pack('!i', param)))
elif isinstance(param, float):
sha.update(bytearray(pack('!f', param)))
else:
print('cannot hash param: %s, %s' % (param, type(param)))

output_file = 'txt2img_%s_%s.png' % (params[0], sha.hexdigest())
output_full = safer_join(output_path, output_file)
Expand Down

0 comments on commit f4ca6a0

Please sign in to comment.