Spaces:
Runtime error
Runtime error
Download src/parser/parser.service.ts from ukzada/invoice-ocr-temp: direct link, hf CLI and curl.
- Browser
- Download file 796 Bytes
-
https://huggingface.co/spaces/ukzada/invoice-ocr-temp/resolve/main/src/parser/parser.service.ts
- Command line
-
hf download hf://spaces/ukzada/invoice-ocr-temp/src/parser/parser.service.ts
-
curl -L -o parser.service.ts https://huggingface.co/spaces/ukzada/invoice-ocr-temp/resolve/main/src/parser/parser.service.ts
796 Bytes
| import { Injectable } from '@nestjs/common'; | |
| () | |
| export class ParserService { | |
| parseInvoice(text: string) { | |
| const invoiceNumber = text.match(/invoice\s*#?\s*([A-Z0-9-]+)/i); | |
| const total = text.match(/total\s*[:$]?\s*([0-9.]+)/i); | |
| const subtotal = text.match(/subtotal\s*[:$]?\s*([0-9.]+)/i); | |
| const tax = text.match(/tax\s*[:$]?\s*([0-9.]+)/i); | |
| const date = text.match(/\d{1,2}\/\d{1,2}\/\d{2,4}/); | |
| return { | |
| vendor_name: text.split('\n')[0], | |
| invoice_number: invoiceNumber?.[1] || null, | |
| invoice_date: date ? new Date(date[0]) : null, | |
| subtotal: subtotal ? parseFloat(subtotal[1]) : null, | |
| tax: tax ? parseFloat(tax[1]) : null, | |
| total: total ? parseFloat(total[1]) : null, | |
| currency: 'USD', | |
| }; | |
| } | |
| } |