fix detection
This commit is contained in:
@@ -484,6 +484,7 @@
|
||||
:show-tour-start-form="showTourStartForm"
|
||||
@add-field="addField"
|
||||
@set-draw="[drawField = $event.field, drawOption = $event.option]"
|
||||
@select-submitter="selectedSubmitter = $event"
|
||||
@set-draw-type="[drawFieldType = $event, showDrawField = true]"
|
||||
@set-drag="dragField = $event"
|
||||
@set-drag-placeholder="$refs.dragPlaceholder.dragPlaceholder = $event"
|
||||
|
||||
@@ -222,7 +222,16 @@
|
||||
width="22"
|
||||
class="animate-spin"
|
||||
/>
|
||||
<span class="hidden md:inline">
|
||||
<span
|
||||
v-if="analyzingProgress"
|
||||
class="hidden md:inline"
|
||||
>
|
||||
{{ Math.round(analyzingProgress * 100) }}% {{ t('analyzing_') }}
|
||||
</span>
|
||||
<span
|
||||
v-else
|
||||
class="hidden md:inline"
|
||||
>
|
||||
{{ fieldPagesLoaded }} / {{ numberOfPages }} {{ t('processing_') }}
|
||||
</span>
|
||||
</template>
|
||||
@@ -363,10 +372,11 @@ export default {
|
||||
default: false
|
||||
}
|
||||
},
|
||||
emits: ['add-field', 'set-draw', 'set-draw-type', 'set-drag', 'drag-end', 'scroll-to-area', 'change-submitter', 'set-drag-placeholder'],
|
||||
emits: ['add-field', 'set-draw', 'set-draw-type', 'set-drag', 'drag-end', 'scroll-to-area', 'change-submitter', 'set-drag-placeholder', 'select-submitter'],
|
||||
data () {
|
||||
return {
|
||||
fieldPagesLoaded: null,
|
||||
analyzingProgress: 0,
|
||||
defaultFieldsSearch: ''
|
||||
}
|
||||
},
|
||||
@@ -448,8 +458,6 @@ export default {
|
||||
while (true) {
|
||||
const { value, done } = await reader.read()
|
||||
|
||||
if (done) break
|
||||
|
||||
buffer += decoder.decode(value, { stream: true })
|
||||
|
||||
const lines = buffer.split('\n\n')
|
||||
@@ -464,10 +472,21 @@ export default {
|
||||
if (data.error) {
|
||||
alert(data.error)
|
||||
|
||||
this.template.fields = data.fields || fields
|
||||
|
||||
break
|
||||
} else if (data.analyzing) {
|
||||
this.analyzingProgress = data.progress
|
||||
} else if (data.completed) {
|
||||
this.fieldPagesLoaded = null
|
||||
this.template.fields = fields
|
||||
|
||||
if (data.submitters) {
|
||||
this.template.submitters = data.submitters
|
||||
this.$emit('select-submitter', this.template.submitters[0])
|
||||
}
|
||||
|
||||
this.template.fields = data.fields || fields
|
||||
|
||||
this.save()
|
||||
|
||||
break
|
||||
@@ -484,11 +503,14 @@ export default {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (done) break
|
||||
}
|
||||
}).catch(error => {
|
||||
console.error('Error in streaming message: ', error)
|
||||
}).finally(() => {
|
||||
this.fieldPagesLoaded = null
|
||||
this.analyzingProgress = null
|
||||
this.isFieldsLoading = false
|
||||
})
|
||||
},
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
const en = {
|
||||
analyzing_: 'Analyzing...',
|
||||
download: 'Download',
|
||||
downloading_: 'Downloading...',
|
||||
view: 'View',
|
||||
@@ -187,6 +188,7 @@ const en = {
|
||||
}
|
||||
|
||||
const es = {
|
||||
analyzing_: 'Analizando...',
|
||||
download: 'Descargar',
|
||||
downloading_: 'Descargando...',
|
||||
view: 'Vista',
|
||||
@@ -374,6 +376,7 @@ const es = {
|
||||
}
|
||||
|
||||
const it = {
|
||||
analyzing_: 'Analisi...',
|
||||
download: 'Scarica',
|
||||
downloading_: 'Download in corso...',
|
||||
view: 'Vista',
|
||||
@@ -561,6 +564,7 @@ const it = {
|
||||
}
|
||||
|
||||
const pt = {
|
||||
analyzing_: 'Analisando...',
|
||||
download: 'Baixar',
|
||||
downloading_: 'Baixando...',
|
||||
view: 'Visualizar',
|
||||
@@ -748,6 +752,7 @@ const pt = {
|
||||
}
|
||||
|
||||
const fr = {
|
||||
analyzing_: 'Analyse...',
|
||||
download: 'Télécharger',
|
||||
downloading_: 'Téléchargement...',
|
||||
view: 'Voir',
|
||||
@@ -935,6 +940,7 @@ const fr = {
|
||||
}
|
||||
|
||||
const de = {
|
||||
analyzing_: 'Analysiere...',
|
||||
download: 'Download',
|
||||
downloading_: 'Download...',
|
||||
view: 'Anzeigen',
|
||||
@@ -1122,6 +1128,7 @@ const de = {
|
||||
}
|
||||
|
||||
const nl = {
|
||||
analyzing_: 'Analyseren...',
|
||||
download: 'Downloaden',
|
||||
downloading_: 'Downloaden...',
|
||||
view: 'Bekijken',
|
||||
|
||||
+1
-3
@@ -100,9 +100,7 @@ Rails.application.routes.draw do
|
||||
resource :debug, only: %i[show], controller: 'templates_debug' if Rails.env.development?
|
||||
resources :documents, only: %i[index create], controller: 'template_documents'
|
||||
resources :clone_and_replace, only: %i[create], controller: 'templates_clone_and_replace'
|
||||
if !Docuseal.multitenant? || Docuseal.demo?
|
||||
resources :detect_fields, only: %i[create], controller: 'templates_detect_fields'
|
||||
end
|
||||
resources :detect_fields, only: %i[create], controller: 'templates_detect_fields' unless Docuseal.multitenant?
|
||||
resources :restore, only: %i[create], controller: 'templates_restore'
|
||||
resources :archived, only: %i[index], controller: 'templates_archived_submissions'
|
||||
resources :submissions, only: %i[new create]
|
||||
|
||||
@@ -39,6 +39,7 @@ Puma::Plugin.create do
|
||||
configs = Sidekiq.configure_embed do |config|
|
||||
config.logger.level = Logger::INFO
|
||||
sidekiq_config = YAML.load_file('config/sidekiq.yml')
|
||||
sidekiq_config['queues'] << 'fields' if ENV['DEMO'] == 'true'
|
||||
config.queues = sidekiq_config['queues']
|
||||
config.concurrency = ENV.fetch('SIDEKIQ_THREADS', 5).to_i
|
||||
config.merge!(sidekiq_config)
|
||||
|
||||
@@ -5,7 +5,7 @@ module Templates
|
||||
module_function
|
||||
|
||||
TextFieldBox = Struct.new(:x, :y, :w, :h, keyword_init: true)
|
||||
PageNode = Struct.new(:prev, :next, :elem, :page, keyword_init: true)
|
||||
PageNode = Struct.new(:prev, :next, :elem, :page, :attachment_uuid, keyword_init: true)
|
||||
|
||||
DATE_REGEXP = /
|
||||
(?:
|
||||
@@ -75,7 +75,7 @@ module Templates
|
||||
{
|
||||
uuid: SecureRandom.uuid,
|
||||
type: f.type,
|
||||
required: true,
|
||||
required: f.type != 'checkbox',
|
||||
preferences: {},
|
||||
areas: [{
|
||||
x: f.x,
|
||||
@@ -90,14 +90,14 @@ module Templates
|
||||
|
||||
yield [attachment&.uuid, 0, fields] if block_given?
|
||||
|
||||
fields
|
||||
[fields, nil]
|
||||
end
|
||||
|
||||
def process_pdf_attachment(io, attachment:, confidence:, nms:, temperature:, inference:,
|
||||
split_page: false, aspect_ratio: false, padding: nil, regexp_type: false)
|
||||
doc = Pdfium::Document.open_bytes(io.read)
|
||||
|
||||
head_node = PageNode.new(elem: ''.b)
|
||||
head_node = PageNode.new(elem: ''.b, page: 0, attachment_uuid: attachment&.uuid)
|
||||
tail_node = head_node
|
||||
|
||||
fields = doc.page_count.times.flat_map do |page_number|
|
||||
@@ -107,7 +107,7 @@ module Templates
|
||||
|
||||
image = Vips::Image.new_from_memory(data, width, height, 4, :uchar)
|
||||
|
||||
fields = inference.call(image, confidence: confidence * 0.1, nms:, split_page:,
|
||||
fields = inference.call(image, confidence: confidence / 4.0, nms:, split_page:,
|
||||
temperature:, aspect_ratio:, padding:)
|
||||
|
||||
text_fields = extract_text_fields_from_page(page)
|
||||
@@ -118,15 +118,17 @@ module Templates
|
||||
|
||||
fields = fields.reject { |f| f.confidence < confidence }
|
||||
|
||||
field_nodes, tail_node = build_page_nodes(page, fields, tail_node)
|
||||
field_nodes, tail_node = build_page_nodes(page, fields, tail_node, attachment_uuid: attachment&.uuid)
|
||||
|
||||
fields = field_nodes.map do |node|
|
||||
field = node.elem
|
||||
|
||||
type = regexp_type ? type_from_page_node(node) : field.type
|
||||
|
||||
{
|
||||
uuid: SecureRandom.uuid,
|
||||
type: regexp_type ? type_from_page_node(node) : field.type,
|
||||
required: true,
|
||||
type:,
|
||||
required: type != 'checkbox',
|
||||
preferences: {},
|
||||
areas: [{
|
||||
x: field.x, y: field.y,
|
||||
@@ -185,7 +187,7 @@ module Templates
|
||||
return 'text'
|
||||
end
|
||||
|
||||
def build_page_nodes(page, fields, tail_node)
|
||||
def build_page_nodes(page, fields, tail_node, attachment_uuid: nil)
|
||||
field_nodes = []
|
||||
current_text = ''.b
|
||||
|
||||
@@ -243,13 +245,13 @@ module Templates
|
||||
|
||||
if process_field_node
|
||||
unless current_text.empty?
|
||||
new_text_node = PageNode.new(prev: tail_node, elem: current_text, page: page.page_index)
|
||||
new_text_node = PageNode.new(prev: tail_node, elem: current_text, page: page.page_index, attachment_uuid:)
|
||||
tail_node.next = new_text_node
|
||||
tail_node = new_text_node
|
||||
current_text = ''.b
|
||||
end
|
||||
|
||||
new_field_node = PageNode.new(prev: tail_node, elem: field, page: page.page_index)
|
||||
new_field_node = PageNode.new(prev: tail_node, elem: field, page: page.page_index, attachment_uuid:)
|
||||
tail_node.next = new_field_node
|
||||
tail_node = new_field_node
|
||||
|
||||
@@ -299,7 +301,7 @@ module Templates
|
||||
end
|
||||
|
||||
unless current_text.empty?
|
||||
new_text_node = PageNode.new(prev: tail_node, elem: current_text, page: page.page_index)
|
||||
new_text_node = PageNode.new(prev: tail_node, elem: current_text, page: page.page_index, attachment_uuid:)
|
||||
tail_node.next = new_text_node
|
||||
tail_node = new_text_node
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user