fixed argument types
This commit is contained in:
@@ -27,6 +27,7 @@ if __name__ == '__main__':
|
|||||||
# get image from minio
|
# get image from minio
|
||||||
buffer = get(
|
buffer = get(
|
||||||
client=minio_client,
|
client=minio_client,
|
||||||
|
bucket_name=BUCKET_NAME,
|
||||||
object_name=obj.object_name,
|
object_name=obj.object_name,
|
||||||
)
|
)
|
||||||
# convert data to image
|
# convert data to image
|
||||||
|
|||||||
@@ -3,16 +3,15 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from io import BytesIO
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from bson import ObjectId
|
from bson import ObjectId
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from pymongo.collection import Collection
|
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 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 shared.utils import check_env, setup_logging
|
||||||
from web_ui.src.main import NECESSARY_ENV_VAR_LIST
|
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)
|
logging.error('failed getting image from document: %s', doc_id)
|
||||||
continue
|
continue
|
||||||
try:
|
try:
|
||||||
# save image to buffer
|
# get image
|
||||||
buffer = BytesIO()
|
image = vis_com.get_image(
|
||||||
vis_com.image.save(buffer, 'png') # type: ignore
|
minio_client=minio_client,
|
||||||
|
)
|
||||||
# put buffer in minio
|
# put buffer in minio
|
||||||
object_name = put(
|
object_name = put_image(
|
||||||
client=minio_client,
|
client=minio_client,
|
||||||
buffer=buffer,
|
image=image,
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logging.debug(exc)
|
logging.debug(exc)
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ from PIL import Image
|
|||||||
from pydantic import BaseModel, ConfigDict
|
from pydantic import BaseModel, ConfigDict
|
||||||
from pymongo.collection import Collection
|
from pymongo.collection import Collection
|
||||||
|
|
||||||
from shared.datastore import get, put
|
from shared.datastore import get_image, put_image
|
||||||
from shared.mongodb.classes import ModelData
|
from shared.mongodb.src.classes import ModelData
|
||||||
|
|
||||||
|
|
||||||
class VisualCommunication(BaseModel):
|
class VisualCommunication(BaseModel):
|
||||||
@@ -39,11 +39,9 @@ class VisualCommunication(BaseModel):
|
|||||||
"""Upload image to MinIO and return MD5 checksum of hashed image."""
|
"""Upload image to MinIO and return MD5 checksum of hashed image."""
|
||||||
assert isinstance(image, Image.Image)
|
assert isinstance(image, Image.Image)
|
||||||
assert isinstance(minio_client, Minio)
|
assert isinstance(minio_client, Minio)
|
||||||
buffer = BytesIO()
|
object_name = put_image(
|
||||||
image.save(buffer, 'png')
|
|
||||||
object_name = put(
|
|
||||||
client=minio_client,
|
client=minio_client,
|
||||||
buffer=buffer,
|
image=image,
|
||||||
)
|
)
|
||||||
return object_name
|
return object_name
|
||||||
|
|
||||||
@@ -92,14 +90,12 @@ class VisualCommunication(BaseModel):
|
|||||||
def get_image(self, minio_client: Minio) -> Image.Image:
|
def get_image(self, minio_client: Minio) -> Image.Image:
|
||||||
"""Load image data from minio."""
|
"""Load image data from minio."""
|
||||||
assert isinstance(minio_client, Minio)
|
assert isinstance(minio_client, Minio)
|
||||||
# get buffer from minio
|
# get image from minio
|
||||||
buffer = get(
|
image = get_image(
|
||||||
client=minio_client,
|
client=minio_client,
|
||||||
object_name=self.object_name,
|
object_name=self.object_name,
|
||||||
)
|
)
|
||||||
# convert data to image
|
return image
|
||||||
im = Image.open(buffer)
|
|
||||||
return im
|
|
||||||
|
|
||||||
def save_to_mongo(self, collection: Collection) -> None:
|
def save_to_mongo(self, collection: Collection) -> None:
|
||||||
"""Save self as document in MongoDB."""
|
"""Save self as document in MongoDB."""
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ from pymongo.collection import Collection
|
|||||||
|
|
||||||
from shared.datastore import delete as delete_from_minio
|
from shared.datastore import delete as delete_from_minio
|
||||||
from shared.mongodb import count_documents, get_visual_communication, upsert_annotation
|
from shared.mongodb import count_documents, get_visual_communication, upsert_annotation
|
||||||
from shared.mongodb.classes import ModelData, VisualCommunication
|
from shared.mongodb.src.classes import ModelData, VisualCommunication
|
||||||
from shared.mongodb.exceptions import NoDocumentFoundException
|
from shared.mongodb.src.exceptions import NoDocumentFoundException
|
||||||
|
|
||||||
from .layout import app_layout
|
from .layout import app_layout
|
||||||
|
|
||||||
@@ -146,8 +146,10 @@ def init_app(
|
|||||||
logging.debug(exc)
|
logging.debug(exc)
|
||||||
failed_filename_list.append(filename)
|
failed_filename_list.append(filename)
|
||||||
# remove document from minio
|
# remove document from minio
|
||||||
|
bucket_name = os.getenv('MINIO_BUCKET_NAME', default='')
|
||||||
delete_from_minio(
|
delete_from_minio(
|
||||||
client=minio_client,
|
client=minio_client,
|
||||||
|
bucket_name=bucket_name,
|
||||||
object_name=vis_com.object_name,
|
object_name=vis_com.object_name,
|
||||||
)
|
)
|
||||||
assert (
|
assert (
|
||||||
|
|||||||
Reference in New Issue
Block a user