updated to use new class
CI Pipeline / Test (pull_request) Successful in 2m7s
CI Pipeline / Build and Publish (./Dockerfile.model, ${{ vars.docker_repo_url }}/${{ gitea.repository }}/model) (pull_request) Successful in 6m26s
CI Pipeline / Build and Publish (./Dockerfile.web_ui, ${{ vars.docker_repo_url }}/${{ gitea.repository }}/web_ui) (pull_request) Successful in 5m40s
CI Pipeline / Test (pull_request) Successful in 2m7s
CI Pipeline / Build and Publish (./Dockerfile.model, ${{ vars.docker_repo_url }}/${{ gitea.repository }}/model) (pull_request) Successful in 6m26s
CI Pipeline / Build and Publish (./Dockerfile.web_ui, ${{ vars.docker_repo_url }}/${{ gitea.repository }}/web_ui) (pull_request) Successful in 5m40s
This commit is contained in:
+47
-29
@@ -16,11 +16,11 @@ from pydantic import ValidationError
|
|||||||
from pymongo.collection import Collection
|
from pymongo.collection import Collection
|
||||||
|
|
||||||
from .layout import app_layout
|
from .layout import app_layout
|
||||||
|
from shared.data_store import delete as delete_from_minio
|
||||||
from shared.database import count_documents
|
from shared.database import count_documents
|
||||||
from shared.database import get_visual_communication
|
from shared.database import get_visual_communication
|
||||||
from shared.database import NoDocumentFoundException
|
from shared.database import NoDocumentFoundException
|
||||||
from shared.database import upsert_annotation
|
from shared.database import upsert_annotation
|
||||||
from shared.database import upsert_visual_communication
|
|
||||||
from shared.database import VisualCommunication
|
from shared.database import VisualCommunication
|
||||||
from shared.dto import ModelData
|
from shared.dto import ModelData
|
||||||
|
|
||||||
@@ -120,34 +120,52 @@ def init_app(
|
|||||||
filename_list: list[str] | None,
|
filename_list: list[str] | None,
|
||||||
) -> tuple[str | None, str | None]:
|
) -> tuple[str | None, str | None]:
|
||||||
"""Upload image to database through web ui."""
|
"""Upload image to database through web ui."""
|
||||||
# stop early if possible
|
try:
|
||||||
if content_list is None or filename_list is None:
|
# stop if no input
|
||||||
logging.info('nothing to upload.')
|
assert (
|
||||||
return None, 'nothing to upload'.title()
|
content_list is not None
|
||||||
# build list of visual communication
|
) and (
|
||||||
vis_com_list = []
|
filename_list is not None
|
||||||
for content, filename in zip(content_list, filename_list):
|
), 'nothing to upload'
|
||||||
try:
|
# handle input
|
||||||
image = VisualCommunication.decode_image(content=content)
|
failed_filename_list = []
|
||||||
vis_com = VisualCommunication(
|
for content, filename in zip(content_list, filename_list):
|
||||||
name=filename,
|
try:
|
||||||
image=image,
|
# decode image content
|
||||||
)
|
image = VisualCommunication.decode_image(content=content)
|
||||||
except Exception as exc:
|
except Exception:
|
||||||
logging.error('failed handling data from file: %s', filename)
|
logging.debug('failed decoding %s', filename)
|
||||||
logging.debug(exc)
|
failed_filename_list.append(filename)
|
||||||
continue
|
continue
|
||||||
vis_com_list.append(vis_com)
|
try:
|
||||||
# upsert documents
|
# instantiate to upload image to minio
|
||||||
success = upsert_visual_communication(
|
vis_com = VisualCommunication.from_name_and_image(
|
||||||
collection=mongo_collection,
|
name=filename,
|
||||||
visual_communication_list=vis_com_list,
|
image=image,
|
||||||
)
|
minio_client=minio_client,
|
||||||
if success:
|
)
|
||||||
logging.info('uploaded %s files to database', len(vis_com_list))
|
except Exception as exc:
|
||||||
return 'successfully uploaded images'.title(), None
|
logging.debug(exc)
|
||||||
logging.error('failed uploading images to database')
|
failed_filename_list.append(filename)
|
||||||
return None, 'failed uploading images'.title()
|
continue
|
||||||
|
try:
|
||||||
|
# save to mongodb
|
||||||
|
vis_com.save_to_mongo(collection=mongo_collection)
|
||||||
|
except Exception as exc:
|
||||||
|
logging.debug(exc)
|
||||||
|
failed_filename_list.append(filename)
|
||||||
|
# remove document from minio
|
||||||
|
delete_from_minio(
|
||||||
|
client=minio_client,
|
||||||
|
object_name=vis_com.object_name,
|
||||||
|
)
|
||||||
|
assert len(failed_filename_list) == 0, f"failed uploading:{
|
||||||
|
'\n'.join(failed_filename_list)
|
||||||
|
}"
|
||||||
|
except Exception as exc:
|
||||||
|
logging.debug(exc)
|
||||||
|
return None, str(exc).title()
|
||||||
|
return 'successfully uploaded images'.title(), None
|
||||||
|
|
||||||
# define callback: cycle visual communication data
|
# define callback: cycle visual communication data
|
||||||
@app.callback(
|
@app.callback(
|
||||||
|
|||||||
Reference in New Issue
Block a user