Skip to content

Commit 9554dfc

Browse files
committed
feat(ocr-translation): report progress
Signed-off-by: Julien Veyssier <julien-nc@posteo.net>
1 parent e67e51d commit 9554dfc

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

lib/TaskProcessing/ImageToTextTranslateProvider.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ public function process(?string $userId, array $input, callable $reportProgress)
104104
throw new RuntimeException('Invalid target_language input');
105105
}
106106

107+
$inputCount = count($input['input']);
108+
107109
// OCR
108110
$ocrInputs = array_map(static function (File $file) {
109111
return $file->getId();
@@ -122,6 +124,10 @@ public function process(?string $userId, array $input, callable $reportProgress)
122124
throw new RuntimeException('OCR sub task failed with: ' . $e->getMessage());
123125
}
124126

127+
// we did half of the work: all the OCR stuff at once
128+
$reportProgress(0.5);
129+
130+
$translationIndex = 0;
125131
$translatedOutputs = [];
126132
foreach ($ocrOutputs as $ocrOutput) {
127133
try {
@@ -137,6 +143,10 @@ public function process(?string $userId, array $input, callable $reportProgress)
137143
);
138144
$taskOutput = $this->taskProcessingService->runTaskProcessingTask($task);
139145
$translatedOutputs[] = $taskOutput['output'];
146+
// report progress
147+
$translationIndex++;
148+
$translationProgress = $translationIndex / $inputCount;
149+
$reportProgress(0.5 + ($translationProgress / 2));
140150
} catch (Exception $e) {
141151
$this->logger->warning('Translation sub task failed with: ' . $e->getMessage(), ['exception' => $e]);
142152
throw new RuntimeException('Translation sub task failed with: ' . $e->getMessage());

0 commit comments

Comments
 (0)