Skip to content
Snippets Groups Projects

Text orientation in base worker

Merged ml bonhomme requested to merge text-orientation into master
All threads resolved!
3 files
+ 131
142
Compare changes
  • Side-by-side
  • Inline
Files
3
@@ -85,7 +85,10 @@ class TranscriptionMixin(object):
transcriptions, list
), "transcriptions shouldn't be null and should be of type list"
for index, transcription in enumerate(transcriptions):
# Create shallow copies of every transcription to avoid mutating the original payload
transcriptions_payload = list(map(dict, transcriptions))
for (index, transcription) in enumerate(transcriptions_payload):
element_id = transcription.get("element_id")
assert element_id and isinstance(
element_id, str
@@ -107,22 +110,14 @@ class TranscriptionMixin(object):
assert orientation and isinstance(
orientation, TextOrientation
), f"Transcription at index {index} in transcriptions: orientation shouldn't be null and should be of type TextOrientation"
transcription["orientation"] = orientation
sent_transcriptions = [
{
"text": transcription["text"],
"score": transcription["score"],
"orientation": transcription["orientation"].value,
}
for transcription in transcriptions
]
if orientation:
transcription["orientation"] = orientation.value
created_trs = self.request(
"CreateTranscriptions",
body={
"worker_version": self.worker_version_id,
"transcriptions": sent_transcriptions,
"transcriptions": transcriptions_payload,
},
)["transcriptions"]
@@ -165,7 +160,10 @@ class TranscriptionMixin(object):
transcriptions, list
), "transcriptions shouldn't be null and should be of type list"
for index, transcription in enumerate(transcriptions):
# Create shallow copies of every transcription to avoid mutating the original payload
transcriptions_payload = list(map(dict, transcriptions))
for (index, transcription) in enumerate(transcriptions_payload):
text = transcription.get("text")
assert text and isinstance(
text, str
@@ -182,7 +180,8 @@ class TranscriptionMixin(object):
assert orientation and isinstance(
orientation, TextOrientation
), f"Transcription at index {index} in transcriptions: orientation shouldn't be null and should be of type TextOrientation"
transcription["orientation"] = orientation
if orientation:
transcription["orientation"] = orientation.value
polygon = transcription.get("polygon")
assert polygon and isinstance(
@@ -203,23 +202,13 @@ class TranscriptionMixin(object):
)
return
sent_transcriptions = [
{
"text": transcription["text"],
"score": transcription["score"],
"orientation": transcription["orientation"].value,
"polygon": transcription["polygon"],
}
for transcription in transcriptions
]
annotations = self.request(
"CreateElementTranscriptions",
id=element.id,
body={
"element_type": sub_element_type,
"worker_version": self.worker_version_id,
"transcriptions": sent_transcriptions,
"transcriptions": transcriptions_payload,
"return_elements": True,
},
)
@@ -267,7 +256,9 @@ class TranscriptionMixin(object):
"element_id": annotation["element_id"],
"text": transcription["text"],
"confidence": transcription["score"],
"orientation": transcription["orientation"].value,
"orientation": transcription["orientation"].value
if "orientation" in transcription
else TextOrientation.HorizontalLeftToRight.value,
"worker_version_id": self.worker_version_id,
}
)
Loading