fixed argument types

This commit is contained in:
brian
2024-12-19 16:01:29 +00:00
parent c9da7378a1
commit 99d5c88c8d
4 changed files with 20 additions and 21 deletions
+1
View File
@@ -27,6 +27,7 @@ if __name__ == '__main__':
# get image from minio
buffer = get(
client=minio_client,
bucket_name=BUCKET_NAME,
object_name=obj.object_name,
)
# convert data to image
+8 -8
View File
@@ -3,16 +3,15 @@
from __future__ import annotations
import logging
from io import BytesIO
from pathlib import Path
from bson import ObjectId
from dotenv import load_dotenv
from pymongo.collection import Collection
from shared.datastore import connect_minio, put
from shared.datastore import connect_minio, put_image
from shared.mongodb import connect_mongodb
from shared.mongodb.classes import VisualCommunication
from shared.mongodb.src.classes import VisualCommunication
from shared.utils import check_env, setup_logging
from web_ui.src.main import NECESSARY_ENV_VAR_LIST
@@ -96,13 +95,14 @@ if __name__ == '__main__':
logging.error('failed getting image from document: %s', doc_id)
continue
try:
# save image to buffer
buffer = BytesIO()
vis_com.image.save(buffer, 'png') # type: ignore
# get image
image = vis_com.get_image(
minio_client=minio_client,
)
# put buffer in minio
object_name = put(
object_name = put_image(
client=minio_client,
buffer=buffer,
image=image,
)
except Exception as exc:
logging.debug(exc)
@@ -12,8 +12,8 @@ from PIL import Image
from pydantic import BaseModel, ConfigDict
from pymongo.collection import Collection
from shared.datastore import get, put
from shared.mongodb.classes import ModelData
from shared.datastore import get_image, put_image
from shared.mongodb.src.classes import ModelData
class VisualCommunication(BaseModel):
@@ -39,11 +39,9 @@ class VisualCommunication(BaseModel):
"""Upload image to MinIO and return MD5 checksum of hashed image."""
assert isinstance(image, Image.Image)
assert isinstance(minio_client, Minio)
buffer = BytesIO()
image.save(buffer, 'png')
object_name = put(
object_name = put_image(
client=minio_client,
buffer=buffer,
image=image,
)
return object_name
@@ -92,14 +90,12 @@ class VisualCommunication(BaseModel):
def get_image(self, minio_client: Minio) -> Image.Image:
"""Load image data from minio."""
assert isinstance(minio_client, Minio)
# get buffer from minio
buffer = get(
# get image from minio
image = get_image(
client=minio_client,
object_name=self.object_name,
)
# convert data to image
im = Image.open(buffer)
return im
return image
def save_to_mongo(self, collection: Collection) -> None:
"""Save self as document in MongoDB."""
+4 -2
View File
@@ -14,8 +14,8 @@ from pymongo.collection import Collection
from shared.datastore import delete as delete_from_minio
from shared.mongodb import count_documents, get_visual_communication, upsert_annotation
from shared.mongodb.classes import ModelData, VisualCommunication
from shared.mongodb.exceptions import NoDocumentFoundException
from shared.mongodb.src.classes import ModelData, VisualCommunication
from shared.mongodb.src.exceptions import NoDocumentFoundException
from .layout import app_layout
@@ -146,8 +146,10 @@ def init_app(
logging.debug(exc)
failed_filename_list.append(filename)
# remove document from minio
bucket_name = os.getenv('MINIO_BUCKET_NAME', default='')
delete_from_minio(
client=minio_client,
bucket_name=bucket_name,
object_name=vis_com.object_name,
)
assert (