Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions mindee/parsing/v2/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,9 @@ def __init__(self, raw_response: StringDict):
self.id = raw_response["id"] if "id" in raw_response else None

def __str__(self) -> str:
alias = f" {self.file.alias}" if self.file.alias else ""
return (
f"Inference\n#########"
f"\nModel\n====="
f"\n:ID: {self.model.id}"
f"\n\nFile\n===="
f"\n:Name: {self.file.name}"
f"\n:Alias:{alias}"
f"{self.result}"
"\n"
f"Inference\n#########\n"
f"{self.model}\n\n"
f"{self.file}"
f"{self.result}\n"
)
17 changes: 16 additions & 1 deletion mindee/parsing/v2/inference_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,24 @@ class InferenceFile:

name: str
"""Name of the file."""
alais: str
alias: str
"""Alias of the file."""
page_count: str
"""Number of pages in the file."""
mime_type: str
"""Mime type of the file."""

def __init__(self, raw_response: StringDict) -> None:
self.name = raw_response["name"]
self.alias = raw_response["alias"]
self.page_count = raw_response["page_count"]
self.mime_type = raw_response["mime_type"]

def __str__(self) -> str:
return (
f"File\n===="
f"\n:Name: {self.name}"
f"\n:Alias:{self.alias if self.alias else ''}"
f"\n:Page Count: {self.page_count}"
f"\n:MIME Type: {self.mime_type}"
)
3 changes: 3 additions & 0 deletions mindee/parsing/v2/inference_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ class InferenceModel:

def __init__(self, raw_response: StringDict) -> None:
self.id = raw_response["id"]

def __str__(self) -> str:
return f"Model\n=====" f"\n:ID: {self.id}"
7 changes: 5 additions & 2 deletions mindee/parsing/v2/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from mindee.parsing.common.string_dict import StringDict
from mindee.parsing.v2.error_response import ErrorResponse
from mindee.parsing.v2.job_webhook import JobWebhook


class Job:
Expand All @@ -26,7 +27,7 @@ class Job:
"""URL to poll for the job status."""
result_url: Optional[str]
"""URL to poll for the job result, redirects to the result if available."""
webhooks: List[str]
webhooks: List[JobWebhook]
"""ID of webhooks associated with the job."""

def __init__(self, raw_response: StringDict) -> None:
Expand All @@ -43,4 +44,6 @@ def __init__(self, raw_response: StringDict) -> None:
self.filename = raw_response["filename"]
self.result_url = raw_response["result_url"]
self.alias = raw_response["alias"]
self.webhooks = raw_response["webhooks"]
self.webhooks = []
for webhook in raw_response["webhooks"]:
self.webhooks.append(JobWebhook(webhook))
36 changes: 36 additions & 0 deletions mindee/parsing/v2/job_webhook.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from datetime import datetime
from typing import Optional

from mindee.parsing.common.string_dict import StringDict
from mindee.parsing.v2.error_response import ErrorResponse


class JobWebhook:
"""JobWebhook information."""

id: str
"""JobWebhook ID."""
created_at: Optional[datetime]
"""Created at date."""
status: str
"""Status of the webhook."""
error: Optional[ErrorResponse]
"""Error response, if any."""

def __init__(self, server_response: StringDict) -> None:
self.id = server_response["id"]
self.created_at = self.parse_date(server_response.get("created_at"))
self.status = server_response["status"]
self.error = (
ErrorResponse(server_response["error"])
if server_response.get("error") is not None
else None
)

@staticmethod
def parse_date(date_string: Optional[str]) -> Optional[datetime]:
"""Parse the date, if present."""
if not date_string:
return None
date_string = date_string.replace("Z", "+00:00")
return datetime.fromisoformat(date_string)
2 changes: 2 additions & 0 deletions tests/v2/test_inference_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,5 +181,7 @@ def test_full_inference_response():

assert isinstance(inference_result.inference.file, InferenceFile)
assert inference_result.inference.file.name == "complete.jpg"
assert inference_result.inference.file.page_count == 1
assert inference_result.inference.file.mime_type == "image/jpeg"
assert not inference_result.inference.file.alias
assert not inference_result.inference.result.options