Cleanup preprocessing

This commit is contained in:
Nicolas Mowen 2024-10-21 15:29:26 -06:00
parent dacdc1e0fe
commit 2381f7a754
2 changed files with 4 additions and 7 deletions

View File

@ -125,8 +125,7 @@ class Embeddings:
def upsert_thumbnail(self, event_id: str, thumbnail: bytes) -> ndarray:
# Convert thumbnail bytes to PIL Image
image = Image.open(io.BytesIO(thumbnail)).convert("RGB")
embedding = self.vision_embedding([image])[0]
embedding = self.vision_embedding([thumbnail])[0]
self.db.execute_sql(
"""
@ -139,12 +138,8 @@ class Embeddings:
return embedding
def batch_upsert_thumbnail(self, event_thumbs: dict[str, bytes]) -> list[ndarray]:
images = [
Image.open(io.BytesIO(thumb)).convert("RGB")
for thumb in event_thumbs.values()
]
ids = list(event_thumbs.keys())
embeddings = self.vision_embedding(images)
embeddings = self.vision_embedding(list(event_thumbs.values()))
items = []

View File

@ -170,6 +170,8 @@ class GenericONNXEmbedding:
if image.startswith("http"):
response = requests.get(image)
image = Image.open(BytesIO(response.content)).convert("RGB")
elif isinstance(image, bytes):
image = Image.open(BytesIO(image)).convert("RGB")
return image