Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the response to JavaScript object instead of string #3

Open
ayungavis opened this issue Aug 2, 2023 · 0 comments
Open

Update the response to JavaScript object instead of string #3

ayungavis opened this issue Aug 2, 2023 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@ayungavis
Copy link
Member

Currently, we used the original response from the Google Cloud Vision API and it's a string with a line break (\n) character for each word. So, we want to make it dynamic. It should have a pattern to choose which text you want to extract from the image.

For example, if we extract Indonesia's resident ID (KTP), we only want to get the name and the date of birth. So, we need to add a pattern to the extract function. It should look like this:

public async extract<T>(image: string, { pattern: string }) {
  // code here
}

and if we call it based on the example above, it should look like this:

interface Response {
  name: string;
  birthdate: string;
}

const extractor = new ImageTextExtraction({ apiKey: 'your-key' });
const response = await extractor<Response>(image, { 
  pattern: 'nama|tanggal lahir' // pattern text based on image
}); 

then, the response should be like this:

{
  name: 'John Doe',
  birthdate: '1 January 2023'
}
@ayungavis ayungavis added the enhancement New feature or request label Aug 2, 2023
@ayungavis ayungavis self-assigned this Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant