fixed deprecated import
This commit is contained in:
@@ -5,7 +5,7 @@ from pathlib import Path
|
|||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
from shared.data_store import connect, get, put_image
|
from shared.data_store import connect_minio, get, put_image
|
||||||
from shared.utils import setup_logging
|
from shared.utils import setup_logging
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@@ -16,7 +16,7 @@ if __name__ == '__main__':
|
|||||||
# setup logging
|
# setup logging
|
||||||
setup_logging()
|
setup_logging()
|
||||||
# connect to minio
|
# connect to minio
|
||||||
minio_client = connect()
|
minio_client = connect_minio()
|
||||||
# list images in bucket
|
# list images in bucket
|
||||||
BUCKET_NAME = 'visual-critical-discourse-analysis'
|
BUCKET_NAME = 'visual-critical-discourse-analysis'
|
||||||
obj_list = minio_client.list_objects(
|
obj_list = minio_client.list_objects(
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
"""Script to move all images from MongoDB to MinIO."""
|
"""Script to move all images from MongoDB to MinIO."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
@@ -9,12 +10,9 @@ 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.data_store import connect as connect_minio
|
from shared.data_store import connect_minio, put
|
||||||
from shared.data_store import put
|
from shared.database import VisualCommunication, connect
|
||||||
from shared.database import connect
|
from shared.utils import check_env, setup_logging
|
||||||
from shared.database import VisualCommunication
|
|
||||||
from shared.utils import check_env
|
|
||||||
from shared.utils import setup_logging
|
|
||||||
|
|
||||||
|
|
||||||
def list_mongo_document_ids(
|
def list_mongo_document_ids(
|
||||||
@@ -98,7 +96,7 @@ if __name__ == '__main__':
|
|||||||
try:
|
try:
|
||||||
# save image to buffer
|
# save image to buffer
|
||||||
buffer = BytesIO()
|
buffer = BytesIO()
|
||||||
vis_com.image.save(buffer, 'png') # type: ignore
|
vis_com.image.save(buffer, 'png') # type: ignore
|
||||||
# put buffer in minio
|
# put buffer in minio
|
||||||
object_name = put(
|
object_name = put(
|
||||||
client=minio_client,
|
client=minio_client,
|
||||||
@@ -110,13 +108,14 @@ if __name__ == '__main__':
|
|||||||
continue
|
continue
|
||||||
# update visual communication in mongodb
|
# update visual communication in mongodb
|
||||||
try:
|
try:
|
||||||
vis_com.image = None # type: ignore
|
vis_com.image = None # type: ignore
|
||||||
vis_com.object_name = object_name
|
vis_com.object_name = object_name
|
||||||
update_visual_communication(collection, vis_com)
|
update_visual_communication(collection, vis_com)
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
logging.debug(exc)
|
logging.debug(exc)
|
||||||
logging.error(
|
logging.error(
|
||||||
'failed updating visual communication %s', vis_com.name,
|
'failed updating visual communication %s',
|
||||||
|
vis_com.name,
|
||||||
)
|
)
|
||||||
continue
|
continue
|
||||||
logging.debug('updated visual communication %s', vis_com.name)
|
logging.debug('updated visual communication %s', vis_com.name)
|
||||||
|
|||||||
@@ -4,11 +4,10 @@ from pathlib import Path
|
|||||||
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
from shared.data_store import connect as connect_minio
|
from shared.data_store import connect_minio
|
||||||
from shared.database import connect as connect_mongo
|
from shared.database import connect as connect_mongo
|
||||||
from shared.database.classes import VisualCommunication
|
from shared.database.classes import VisualCommunication
|
||||||
from shared.utils import check_env
|
from shared.utils import check_env, setup_logging
|
||||||
from shared.utils import setup_logging
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# load in env file
|
# load in env file
|
||||||
@@ -31,8 +30,7 @@ if __name__ == '__main__':
|
|||||||
# instantiate data object
|
# instantiate data object
|
||||||
vis_com_list = [
|
vis_com_list = [
|
||||||
VisualCommunication.from_file(path, minio_client=minio_client)
|
VisualCommunication.from_file(path, minio_client=minio_client)
|
||||||
for path
|
for path in img_path_list
|
||||||
in img_path_list
|
|
||||||
]
|
]
|
||||||
# generate random predictions
|
# generate random predictions
|
||||||
for vis_com in vis_com_list:
|
for vis_com in vis_com_list:
|
||||||
|
|||||||
@@ -4,13 +4,9 @@ from pathlib import Path
|
|||||||
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
from shared.data_store import (
|
from shared.data_store import connect_minio
|
||||||
connect as connect_minio,
|
from shared.database import connect, get_visual_communication
|
||||||
)
|
from shared.utils import check_env, setup_logging
|
||||||
from shared.database import connect
|
|
||||||
from shared.database import get_visual_communication
|
|
||||||
from shared.utils import check_env
|
|
||||||
from shared.utils import setup_logging
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# load in env file
|
# load in env file
|
||||||
|
|||||||
@@ -5,11 +5,10 @@ from pathlib import Path
|
|||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from pymongo.errors import DuplicateKeyError
|
from pymongo.errors import DuplicateKeyError
|
||||||
|
|
||||||
from shared.data_store import connect as connect_minio
|
from shared.data_store import connect_minio
|
||||||
from shared.database import connect as connect_mongo
|
from shared.database import connect as connect_mongo
|
||||||
from shared.database.classes import VisualCommunication
|
from shared.database.classes import VisualCommunication
|
||||||
from shared.utils import check_env
|
from shared.utils import check_env, setup_logging
|
||||||
from shared.utils import setup_logging
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# load in env file
|
# load in env file
|
||||||
@@ -32,8 +31,7 @@ if __name__ == '__main__':
|
|||||||
# instantiate data object
|
# instantiate data object
|
||||||
vis_com_list = [
|
vis_com_list = [
|
||||||
VisualCommunication.from_file(path, minio_client=minio_client)
|
VisualCommunication.from_file(path, minio_client=minio_client)
|
||||||
for path
|
for path in img_path_list
|
||||||
in img_path_list
|
|
||||||
]
|
]
|
||||||
for vis_com in vis_com_list:
|
for vis_com in vis_com_list:
|
||||||
print(repr(vis_com))
|
print(repr(vis_com))
|
||||||
|
|||||||
@@ -5,11 +5,10 @@ from pathlib import Path
|
|||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from pymongo.errors import DuplicateKeyError
|
from pymongo.errors import DuplicateKeyError
|
||||||
|
|
||||||
from shared.data_store import connect as connect_minio
|
from shared.data_store import connect_minio
|
||||||
from shared.database import connect as connect_mongo
|
|
||||||
from shared.database import VisualCommunication
|
from shared.database import VisualCommunication
|
||||||
from shared.utils import check_env
|
from shared.database import connect as connect_mongo
|
||||||
from shared.utils import setup_logging
|
from shared.utils import check_env, setup_logging
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# load in env file
|
# load in env file
|
||||||
@@ -28,16 +27,17 @@ if __name__ == '__main__':
|
|||||||
ext_img_dir = Path('/Volumes/BW-PSSD/Mixed Methods/')
|
ext_img_dir = Path('/Volumes/BW-PSSD/Mixed Methods/')
|
||||||
assert ext_img_dir.exists()
|
assert ext_img_dir.exists()
|
||||||
img_path_list = [
|
img_path_list = [
|
||||||
path for path in ext_img_dir.glob(
|
path
|
||||||
|
for path in ext_img_dir.glob(
|
||||||
'*.jpg',
|
'*.jpg',
|
||||||
) if path.is_file()
|
)
|
||||||
|
if path.is_file()
|
||||||
]
|
]
|
||||||
print(f"found {len(img_path_list)} images")
|
print(f"found {len(img_path_list)} images")
|
||||||
# create visual communication objects
|
# create visual communication objects
|
||||||
vis_com_list = [
|
vis_com_list = [
|
||||||
VisualCommunication.from_file(path, minio_client=minio_client)
|
VisualCommunication.from_file(path, minio_client=minio_client)
|
||||||
for path
|
for path in img_path_list
|
||||||
in img_path_list
|
|
||||||
]
|
]
|
||||||
print(f"created {len(vis_com_list)} visual communication objects")
|
print(f"created {len(vis_com_list)} visual communication objects")
|
||||||
# upload images
|
# upload images
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ from dotenv import load_dotenv
|
|||||||
from torchinfo import summary
|
from torchinfo import summary
|
||||||
|
|
||||||
from model.src.models import VisualCommunicationModel
|
from model.src.models import VisualCommunicationModel
|
||||||
from shared.data_store import connect, put_model
|
from shared.data_store import connect_minio, put_model
|
||||||
from shared.utils import setup_logging
|
from shared.utils import setup_logging
|
||||||
|
|
||||||
DEVICE = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
DEVICE = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
||||||
@@ -20,7 +20,7 @@ if __name__ == '__main__':
|
|||||||
# setup logging
|
# setup logging
|
||||||
setup_logging()
|
setup_logging()
|
||||||
# connect to minio
|
# connect to minio
|
||||||
client = connect()
|
client = connect_minio()
|
||||||
# instantiate model
|
# instantiate model
|
||||||
model = VisualCommunicationModel().to(DEVICE)
|
model = VisualCommunicationModel().to(DEVICE)
|
||||||
# show model weights
|
# show model weights
|
||||||
|
|||||||
@@ -4,12 +4,11 @@ from pathlib import Path
|
|||||||
|
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
from shared.data_store import connect as connect_minio
|
from shared.data_store import connect_minio
|
||||||
from shared.database import connect as connect_mongo
|
from shared.database import connect as connect_mongo
|
||||||
from shared.database import upsert_prediction
|
from shared.database import upsert_prediction
|
||||||
from shared.database.classes import VisualCommunication
|
from shared.database.classes import VisualCommunication
|
||||||
from shared.utils import check_env
|
from shared.utils import check_env, setup_logging
|
||||||
from shared.utils import setup_logging
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# load in env file
|
# load in env file
|
||||||
@@ -31,8 +30,7 @@ if __name__ == '__main__':
|
|||||||
# instantiate data object
|
# instantiate data object
|
||||||
vis_com_list = [
|
vis_com_list = [
|
||||||
VisualCommunication.from_file(path, minio_client=minio_client)
|
VisualCommunication.from_file(path, minio_client=minio_client)
|
||||||
for path
|
for path in img_path_list
|
||||||
in img_path_list
|
|
||||||
]
|
]
|
||||||
# generate random predictions
|
# generate random predictions
|
||||||
for vis_com in vis_com_list:
|
for vis_com in vis_com_list:
|
||||||
|
|||||||
+5
-4
@@ -1,13 +1,14 @@
|
|||||||
"""Definition of web_ui main script."""
|
"""Definition of web_ui main script."""
|
||||||
|
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from .app import init_app
|
from shared.data_store import connect_minio
|
||||||
from shared.data_store import connect as connect_minio
|
|
||||||
from shared.database import connect
|
from shared.database import connect
|
||||||
from shared.utils import check_env
|
from shared.utils import check_env, setup_logging
|
||||||
from shared.utils import setup_logging
|
|
||||||
|
from .app import init_app
|
||||||
|
|
||||||
# ensure env vars set
|
# ensure env vars set
|
||||||
check_env()
|
check_env()
|
||||||
|
|||||||
Reference in New Issue
Block a user