fixed types
Code Quality Pipeline / Check Code (pull_request) Successful in 3m15s

This commit is contained in:
brian
2025-01-06 13:42:21 +00:00
parent 16ad2b80ee
commit aff0ae8fc6
16 changed files with 88 additions and 74 deletions
+10 -9
View File
@@ -8,11 +8,10 @@ import os
import dash_bootstrap_components as dbc
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 shared.datastore import delete as delete_from_minio
from shared.datastore import Datastore
from shared.mongodb import count_documents, get_visual_communication, upsert_annotation
from shared.mongodb.src.classes import ModelData, VisualCommunication
from shared.mongodb.src.exceptions import NoDocumentFoundException
@@ -22,9 +21,12 @@ from .layout import app_layout
def init_app(
mongo_collection: Collection,
minio_client: Minio,
datastore: Datastore,
) -> Dash:
"""Initialise web UI application."""
assert isinstance(mongo_collection, Collection)
assert isinstance(datastore, Datastore)
assert datastore._client is not None
# setup app
app = Dash(
name='visual_critical_discourse_analysis_web_ui',
@@ -129,11 +131,12 @@ def init_app(
failed_filename_list.append(filename)
continue
try:
assert datastore._client is not None
# instantiate to upload image to minio
vis_com = VisualCommunication.from_name_and_image(
name=filename,
image=image,
minio_client=minio_client,
minio_client=datastore._client,
)
except Exception as exc:
logging.debug(exc)
@@ -146,10 +149,7 @@ 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,
datastore._delete(
object_name=vis_com.object_name,
)
assert (
@@ -240,7 +240,8 @@ def init_app(
)
# set variables
vis_com_name = vis_com.name
image_src = vis_com.webencoded_image(minio_client=minio_client)
assert datastore._client is not None
image_src = vis_com.webencoded_image(minio_client=datastore._client)
if vis_com.prediction is not None:
# TODO: update to use optional predictions
pass
+4 -3
View File
@@ -4,7 +4,7 @@ from __future__ import annotations
import os
from shared.datastore import connect_minio
from shared.datastore import Datastore
from shared.mongodb import connect_mongodb
from shared.utils import check_env, setup_logging
@@ -34,12 +34,13 @@ setup_logging()
collection, db, client = connect_mongodb()
# connect to minio
minio_client = connect_minio()
datastore = Datastore()
datastore.connect()
# initialise application
app = init_app(
mongo_collection=collection,
minio_client=minio_client,
datastore=datastore,
)
server = app.server
server.config.update(SECRET_KEY=os.urandom(24))