renamed module

This commit is contained in:
brian
2024-10-20 20:00:13 +00:00
parent d1ee43e135
commit e2338ad710
26 changed files with 63 additions and 82 deletions
+24 -35
View File
@@ -1,28 +1,28 @@
"""Definition of init_app function."""
from __future__ import annotations
import logging
import os
import dash_bootstrap_components as dbc
from dash import ALL
from dash import Dash
from dash import Input
from dash import Output
from dash import State
from dash import ALL, Dash, Input, Output, State
from dash_auth import BasicAuth
from minio import Minio
from pydantic import ValidationError
from pymongo.collection import Collection
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 get_visual_communication
from shared.database import NoDocumentFoundException
from shared.database import upsert_annotation
from shared.database import VisualCommunication
from shared.dto import ModelData
from shared.mongodb import (
NoDocumentFoundException,
VisualCommunication,
count_documents,
get_visual_communication,
upsert_annotation,
)
from .layout import app_layout
def init_app(
@@ -101,10 +101,8 @@ def init_app(
collection=mongo_collection,
only_with_annotation=True,
)
limit = int(num_total/20)
label_str = f"{
num_handled
}/{num_total}" if num_handled >= limit else ''
limit = int(num_total / 20)
label_str = f'{num_handled}/{num_total}' if num_handled >= limit else ''
return num_handled, num_total, label_str
# define callback: upload image
@@ -122,9 +120,7 @@ def init_app(
"""Upload image to database through web ui."""
try:
# stop if no input
assert (
content_list is not None
) and (
assert (content_list is not None) and (
filename_list is not None
), 'nothing to upload'
# handle input
@@ -159,7 +155,9 @@ def init_app(
client=minio_client,
object_name=vis_com.object_name,
)
assert len(failed_filename_list) == 0, f"failed uploading:{
assert (
len(failed_filename_list) == 0
), f"failed uploading:{
'\n'.join(failed_filename_list)
}"
except Exception as exc:
@@ -208,30 +206,19 @@ def init_app(
logging.info('saving annotations to database: %s', vis_com_name)
try:
# extract option keys
annotation_keys = [
elem['index']
for elem in annotation_keys
]
annotation_keys = [elem['index'] for elem in annotation_keys]
# ensure all options are set
logging.info(annotation_keys)
for option, value in zip(annotation_keys, annotation_values):
if value is None:
raise ValueError(f"{option} is not set")
# prepare data to save
annotation_keys = [
elem.replace(' ', '_')
for elem
in annotation_keys
]
annotation_keys = [elem.replace(' ', '_') for elem in annotation_keys]
annotation_values = [
elem.replace(' ', '_').lower()
for elem
in annotation_values
elem.replace(' ', '_').lower() for elem in annotation_values
]
annotation_map = {
key: value
for key, value
in zip(annotation_keys, annotation_values)
key: value for key, value in zip(annotation_keys, annotation_values)
}
# instantiate ModelOutputs object
annotations = ModelData.from_annotations(**annotation_map)
@@ -273,8 +260,10 @@ def init_app(
response[2] = image_src
response[3] = annotation_values
logging.info(
'finished getting visual communication: %s', vis_com_name,
'finished getting visual communication: %s',
vis_com_name,
)
return tuple(response)
logging.info('initialised app')
return app
+1 -1
View File
@@ -5,7 +5,7 @@ from __future__ import annotations
import os
from shared.data_store import connect_minio
from shared.database import connect_mongodb
from shared.mongodb import connect_mongodb
from shared.utils import check_env, setup_logging
from .app import init_app