flake8 compliant

This commit is contained in:
Brian Bjarke Jensen
2024-02-24 23:42:55 +01:00
parent 993c9a122b
commit fa2230d5cf
23 changed files with 157 additions and 106 deletions
+33 -17
View File
@@ -25,6 +25,11 @@ from src.model_textual import (
SalienceModelOutput
)
class NoDocumentFoundException(Exception):
pass
class ModelOutputs(BaseModel):
visual_syntax: VisualSyntaxModelOutput
contact: ContactModelOutput
@@ -52,7 +57,7 @@ class ModelOutputs(BaseModel):
in cls.model_fields.items()
}
return cls(**kwargs)
@classmethod
def from_annotations(
cls,
@@ -70,17 +75,28 @@ class ModelOutputs(BaseModel):
) -> ModelOutputs:
"""Instantiate from annotation."""
kwargs = {
"visual_syntax": VisualSyntaxModelOutput.from_choice(visual_syntax),
"contact": ContactModelOutput.from_choice(contact),
"angle": AngleModelOutput.from_choice(angle),
"point_of_view": PointOfViewModelOutput.from_choice(point_of_view),
"distance": DistanceModelOutput.from_choice(distance),
"modality_lighting": ModalityLightingModelOutput.from_choice(modality_lighting),
"modality_color": ModalityColorModelOutput.from_choice(modality_color),
"modality_depth": ModalityDepthModelOutput.from_choice(modality_depth),
"information_value": InformationValueModelOutput.from_choice(information_value),
"framing": FramingModelOutput.from_choice(framing),
"salience": SalienceModelOutput.from_choice(salience)
"visual_syntax": VisualSyntaxModelOutput
.from_choice(visual_syntax),
"contact": ContactModelOutput
.from_choice(contact),
"angle": AngleModelOutput
.from_choice(angle),
"point_of_view": PointOfViewModelOutput
.from_choice(point_of_view),
"distance": DistanceModelOutput
.from_choice(distance),
"modality_lighting": ModalityLightingModelOutput
.from_choice(modality_lighting),
"modality_color": ModalityColorModelOutput
.from_choice(modality_color),
"modality_depth": ModalityDepthModelOutput
.from_choice(modality_depth),
"information_value": InformationValueModelOutput
.from_choice(information_value),
"framing": FramingModelOutput
.from_choice(framing),
"salience": SalienceModelOutput
.from_choice(salience)
}
return cls(**kwargs)
@@ -115,7 +131,10 @@ class VisualCommunication(BaseModel):
@field_validator("image", mode="before")
@classmethod
def convert_to_image(cls, image: Image.Image | BytesIO | bytes) -> Image.Image:
def convert_to_image(
cls,
image: Image.Image | BytesIO | bytes
) -> Image.Image:
if isinstance(image, bytes):
image = BytesIO(image)
if isinstance(image, BytesIO):
@@ -124,7 +143,7 @@ class VisualCommunication(BaseModel):
def __repr__(self) -> str:
return f"{self.classname()}(name='{self.name}')"
def webencoded_image(self) -> str:
"""Convert image to be displayed on webpage."""
# convert images to bytes string
@@ -138,6 +157,3 @@ class VisualCommunication(BaseModel):
if not force and self.prediction is not None:
logging.warning("set force=True to overwrite existing values.")
self.prediction = ModelOutputs.from_random()
class NoDocumentFoundException(Exception):
pass