pre-commit renamed files to PEP standard and removed unused imports
pipeline / Test (push) Failing after 51s
pipeline / Test (push) Failing after 51s
This commit is contained in:
+40
-42
@@ -1,29 +1,27 @@
|
||||
from __future__ import annotations
|
||||
from pydantic import BaseModel, field_validator, field_serializer
|
||||
from PIL import Image
|
||||
|
||||
import logging
|
||||
from base64 import b64encode
|
||||
from io import BytesIO
|
||||
from pathlib import Path
|
||||
from base64 import b64encode
|
||||
import logging
|
||||
from typing import List
|
||||
|
||||
from src.model_experiential import (
|
||||
VisualSyntaxModelOutput
|
||||
)
|
||||
from src.model_interpersonal import (
|
||||
ContactModelOutput,
|
||||
AngleModelOutput,
|
||||
PointOfViewModelOutput,
|
||||
DistanceModelOutput,
|
||||
ModalityLightingModelOutput,
|
||||
ModalityColorModelOutput,
|
||||
ModalityDepthModelOutput
|
||||
)
|
||||
from src.model_textual import (
|
||||
InformationValueModelOutput,
|
||||
FramingModelOutput,
|
||||
SalienceModelOutput
|
||||
from model_experiential import (
|
||||
VisualSyntaxModelOutput,
|
||||
)
|
||||
from model_interpersonal import AngleModelOutput
|
||||
from model_interpersonal import ContactModelOutput
|
||||
from model_interpersonal import DistanceModelOutput
|
||||
from model_interpersonal import ModalityColorModelOutput
|
||||
from model_interpersonal import ModalityDepthModelOutput
|
||||
from model_interpersonal import ModalityLightingModelOutput
|
||||
from model_interpersonal import PointOfViewModelOutput
|
||||
from model_textual import FramingModelOutput
|
||||
from model_textual import InformationValueModelOutput
|
||||
from model_textual import SalienceModelOutput
|
||||
from PIL import Image
|
||||
from pydantic import BaseModel
|
||||
from pydantic import field_serializer
|
||||
from pydantic import field_validator
|
||||
|
||||
|
||||
class NoDocumentFoundException(Exception):
|
||||
@@ -44,7 +42,7 @@ class ModelOutputs(BaseModel):
|
||||
salience: SalienceModelOutput
|
||||
|
||||
@classmethod
|
||||
def list_fields(cls) -> List[str]:
|
||||
def list_fields(cls) -> list[str]:
|
||||
"""List options that are stored as attributes."""
|
||||
return list(cls.model_fields.keys())
|
||||
|
||||
@@ -71,32 +69,32 @@ class ModelOutputs(BaseModel):
|
||||
modality_depth: str,
|
||||
information_value: str,
|
||||
framing: str,
|
||||
salience: str
|
||||
salience: str,
|
||||
) -> ModelOutputs:
|
||||
"""Instantiate from annotation."""
|
||||
kwargs = {
|
||||
"visual_syntax": VisualSyntaxModelOutput
|
||||
'visual_syntax': VisualSyntaxModelOutput
|
||||
.from_choice(visual_syntax),
|
||||
"contact": ContactModelOutput
|
||||
'contact': ContactModelOutput
|
||||
.from_choice(contact),
|
||||
"angle": AngleModelOutput
|
||||
'angle': AngleModelOutput
|
||||
.from_choice(angle),
|
||||
"point_of_view": PointOfViewModelOutput
|
||||
'point_of_view': PointOfViewModelOutput
|
||||
.from_choice(point_of_view),
|
||||
"distance": DistanceModelOutput
|
||||
'distance': DistanceModelOutput
|
||||
.from_choice(distance),
|
||||
"modality_lighting": ModalityLightingModelOutput
|
||||
'modality_lighting': ModalityLightingModelOutput
|
||||
.from_choice(modality_lighting),
|
||||
"modality_color": ModalityColorModelOutput
|
||||
'modality_color': ModalityColorModelOutput
|
||||
.from_choice(modality_color),
|
||||
"modality_depth": ModalityDepthModelOutput
|
||||
'modality_depth': ModalityDepthModelOutput
|
||||
.from_choice(modality_depth),
|
||||
"information_value": InformationValueModelOutput
|
||||
'information_value': InformationValueModelOutput
|
||||
.from_choice(information_value),
|
||||
"framing": FramingModelOutput
|
||||
'framing': FramingModelOutput
|
||||
.from_choice(framing),
|
||||
"salience": SalienceModelOutput
|
||||
.from_choice(salience)
|
||||
'salience': SalienceModelOutput
|
||||
.from_choice(salience),
|
||||
}
|
||||
return cls(**kwargs)
|
||||
|
||||
@@ -123,17 +121,17 @@ class VisualCommunication(BaseModel):
|
||||
image.load()
|
||||
return VisualCommunication(name=name, image=image)
|
||||
|
||||
@field_serializer("image")
|
||||
@field_serializer('image')
|
||||
def serialize_image(image: Image.Image) -> bytes: # type: ignore
|
||||
buffer = BytesIO()
|
||||
image.save(buffer, format="JPEG")
|
||||
image.save(buffer, format='JPEG')
|
||||
return buffer.getvalue()
|
||||
|
||||
@field_validator("image", mode="before")
|
||||
@field_validator('image', mode='before')
|
||||
@classmethod
|
||||
def convert_to_image(
|
||||
cls,
|
||||
image: Image.Image | BytesIO | bytes
|
||||
image: Image.Image | BytesIO | bytes,
|
||||
) -> Image.Image:
|
||||
if isinstance(image, bytes):
|
||||
image = BytesIO(image)
|
||||
@@ -148,12 +146,12 @@ class VisualCommunication(BaseModel):
|
||||
"""Convert image to be displayed on webpage."""
|
||||
# convert images to bytes string
|
||||
buffer = BytesIO()
|
||||
self.image.save(buffer, format="png")
|
||||
img_enc = b64encode(buffer.getvalue()).decode("utf-8")
|
||||
self.image.save(buffer, format='png')
|
||||
img_enc = b64encode(buffer.getvalue()).decode('utf-8')
|
||||
return f"data:image/png;base64, {img_enc}"
|
||||
|
||||
def generate_random_prediction(self, force: bool = False) -> None:
|
||||
"""Generate random prediction values."""
|
||||
if not force and self.prediction is not None:
|
||||
logging.warning("set force=True to overwrite existing values.")
|
||||
logging.warning('set force=True to overwrite existing values.')
|
||||
self.prediction = ModelOutputs.from_random()
|
||||
|
||||
Reference in New Issue
Block a user