Skip to content

Commit

Permalink
fix: ocr
Browse files Browse the repository at this point in the history
  • Loading branch information
oott123 committed Mar 22, 2024
1 parent d550737 commit f81c8da
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/search/image-index.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,25 @@ export class ImageIndexService {
}
const textList = [message.text]
const ocrRaw: any[] = []
for (const image of images) {
if (image.type !== 'base64') {
throw new Error('TODO')
}
const buf = Buffer.from(image.data, 'base64')
debug(`getting image buffer, size ${buf.length}`, buf)

const ocrResult = await this.ocr.recognize(buf)
ocrRaw.push(ocrResult)
try {
for (const image of images) {
if (image.type !== 'base64') {
throw new Error('TODO')
}
const buf = Buffer.from(image.data, 'base64')
debug(`getting image buffer, size ${buf.length}`, buf)

const ocrResult = await this.ocr.recognize(buf)
ocrRaw.push(ocrResult)

const text = ocrResult.map((x) => x.text).join('\n')
textList.push(text)
const text = ocrResult.map((x) => x.text).join('\n')
textList.push(text)
}
} catch (e) {
debug('unable to process ocr, skipping it', e)
}

const searchable = textList
.filter((x) => x)
.join('\n')
Expand Down

0 comments on commit f81c8da

Please sign in to comment.