Skip to content
Snippets Groups Projects
Commit 38cec9a1 authored by Marcus Johansson's avatar Marcus Johansson
Browse files

Chose model

parent 68ea2284
No related branches found
Tags 6.22
No related merge requests found
......@@ -150,11 +150,31 @@ class FileToTextBase extends AiInterpolatorFieldRule implements AiInterpolatorFi
'auto' => $this->t('Auto'),
'fast' => $this->t('Fast'),
'hi_res' => $this->t('Hi-Res'),
'ocr_only' => $this->t('OCR Only'),
],
'#description' => $this->t('The strategy to use to partition PDF/Image.'),
'#default_value' => $fieldDefinition->getConfig($entity->bundle())->getThirdPartySetting('ai_interpolator', 'interpolator_unstructured_strategy', 'auto'),
];
$form['interpolator_unstructured_hires_model'] = [
'#type' => 'select',
'#title' => 'Hi-Res Model',
'#options' => [
'default' => $this->t('Default'),
'detectron2_onnx' => $this->t('Detectron2 with ONNX'),
'yolox' => $this->t('YOLOX'),
'yolox_quantized' => $this->t('YOLOX Quantized'),
'chipper' => $this->t('Chipper'),
],
'#description' => $this->t('The Hi-Res model to use.'),
'#default_value' => $fieldDefinition->getConfig($entity->bundle())->getThirdPartySetting('ai_interpolator', 'interpolator_unstructured_strategy', 'auto'),
'#states' => [
'visible' => [
':input[name="interpolator_unstructured_strategy"]' => ['value' => 'hi_res'],
],
],
];
$form['interpolator_unstructured_images'] = [
'#type' => 'checkbox',
'#title' => 'Extract Images',
......@@ -194,9 +214,7 @@ class FileToTextBase extends AiInterpolatorFieldRule implements AiInterpolatorFi
continue;
}
}
$extract = [
'infer_table_structure' => TRUE,
];
$extract = [];
if ($interpolatorConfig['unstructured_images']) {
$extract = [
'extract_image_block_types' => [
......@@ -208,6 +226,9 @@ class FileToTextBase extends AiInterpolatorFieldRule implements AiInterpolatorFi
if ($interpolatorConfig['unstructured_strategy'] !== 'auto') {
$extract['strategy'] = $interpolatorConfig['unstructured_strategy'];
}
if ($interpolatorConfig['unstructured_hires_model'] !== 'default') {
$extract['hi_res_model_name'] = $interpolatorConfig['unstructured_hires_model'];
}
$response = $this->unstructuredApi->structure($fileEntity, $extract);
switch ($interpolatorConfig['unstructured_output_format']) {
......
......@@ -174,6 +174,9 @@ class FileToImage extends AiInterpolatorFieldRule implements AiInterpolatorField
if ($interpolatorConfig['unstructured_strategy'] !== 'auto') {
$extract['strategy'] = $interpolatorConfig['unstructured_strategy'];
}
if ($interpolatorConfig['unstructured_hires_model'] !== 'default') {
$extract['hi_res_model_name'] = $interpolatorConfig['unstructured_hires_model'];
}
$response = $this->unstructuredApi->structure($fileEntity, $extract);
foreach ($response as $result) {
if ($result['type'] == 'Image') {
......
......@@ -136,6 +136,25 @@ class FileToTable extends AiInterpolatorFieldRule implements AiInterpolatorField
'#default_value' => $fieldDefinition->getConfig($entity->bundle())->getThirdPartySetting('ai_interpolator', 'interpolator_unstructured_strategy', 'auto'),
];
$form['interpolator_unstructured_hires_model'] = [
'#type' => 'select',
'#title' => 'Hi-Res Model',
'#options' => [
'default' => $this->t('Default'),
'detectron2_onnx' => $this->t('Detectron2 with ONNX'),
'yolox' => $this->t('YOLOX'),
'yolox_quantized' => $this->t('YOLOX Quantized'),
'chipper' => $this->t('Chipper'),
],
'#description' => $this->t('The Hi-Res model to use.'),
'#default_value' => $fieldDefinition->getConfig($entity->bundle())->getThirdPartySetting('ai_interpolator', 'interpolator_unstructured_strategy', 'auto'),
'#states' => [
'visible' => [
':input[name="interpolator_unstructured_strategy"]' => ['value' => 'hi_res'],
],
],
];
return $form;
}
......@@ -156,6 +175,9 @@ class FileToTable extends AiInterpolatorFieldRule implements AiInterpolatorField
if ($interpolatorConfig['unstructured_strategy'] !== 'auto') {
$extract['strategy'] = $interpolatorConfig['unstructured_strategy'];
}
if ($interpolatorConfig['unstructured_hires_model'] !== 'default') {
$extract['hi_res_model_name'] = $interpolatorConfig['unstructured_hires_model'];
}
$response = $this->unstructuredApi->structure($fileEntity, $extract);
foreach ($response as $result) {
......
......@@ -100,9 +100,10 @@ class UnstructuredApi {
if (!$this->baseHost) {
throw new \Exception('No base host set.');
}
// We can wait long time since its video.
// We can wait long time since its expensive API calls.
$options['connect_timeout'] = 600;
$options['read_timeout'] = 600;
$options['timeout'] = 600;
// Don't let Guzzle die, just forward body and status.
$options['http_errors'] = FALSE;
// Basic auth.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment