INNER CODE UNIT · Python
random_product_id
patrickjohncyh/fashion-clip · fashion_clip/fashion_clip.py:76
def random_product_id(self):
return self.ids[random.randint(0, len(self.ids))]
def _retrieve_row(self, id: str):
return self.catalog[self.id_to_idx[id]]
# def get_metadata(self, id, fields=['caption', 'price']):
# pass
def _hash_list(self, l: List[str]):
l_hash = map(lambda el: hashlib.sha256(str(el).encode()).hexdigest(), l)
l_hash = ' '.join(l_hash)
return hashlib.sha256(l_hash.encode()).hexdigest()
def hash(self):
id_hash = self._hash_list(self.ids)
images_hash = self._hash_list(self.images)
caption_hash = self._hash_list(self.captions)
return hashlib.sha256((id_hash+images_hash+caption_hash).encode()).hexdigest()