This code helps you calculating the SHA256 hash of a file in Python. This could be helpful for the disambiguation of different files.
def hash_jpg(file: Union[str, Path]) -> str:
block_size = 65536
file_hash = hashlib.sha256()
with open(str(file), 'rb') as fp:
fb = fp.read(block_size)
while len(fb) > 0:
file_hash.update(fb)
fb = fp.read(block_size)
return str(file_hash.hexdigest())
It’s very useful!
Let's talk!
I'm Carlo Nicolini — I am interested on the reliability of AI reasoning systems (interpretability, inference-time methods, probabilistic language programming) and on quantitative portfolio optimization (I am a maintainer of skfolio). If you're working on something in these areas and think we might collaborate, chat, discuss, I'm happy to talk about it!
The best way to reach me is on via DM on LinkedIn.