Skip to content

Commit

Permalink
🎉 feat: Initial commit
Browse files Browse the repository at this point in the history
Add some OCR end points
  • Loading branch information
HarshKapadia2 committed Oct 18, 2021
0 parents commit e6bb49b
Show file tree
Hide file tree
Showing 9 changed files with 315 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
27 changes: 27 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"arrowParens": "always",
"bracketSpacing": true,
"cursorOffset": -1,
"embeddedLanguageFormatting": "auto",
"endOfLine": "auto",
"filepath": "",
"htmlWhitespaceSensitivity": "css",
"insertPragma": false,
"jsxBracketSameLine": false,
"jsxSingleQuote": false,
"overrides": [],
"plugins": [],
"pluginSearchDirs": [],
"printWidth": 80,
"proseWrap": "preserve",
"quoteProps": "preserve",
"rangeEnd": -1,
"rangeStart": 0,
"requirePragma": false,
"semi": true,
"singleQuote": false,
"tabWidth": 4,
"trailingComma": "none",
"useTabs": true,
"vueIndentScriptAndStyle": false
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 NanoNet Technologies Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# nanonets

[NanoNets](https://nanonets.com)' Optical Character Recognition and Image Classification Node.js SDK.

NOTE: This SDK is under development. **Please do not use in production.**

Example usage:

```javascript
import { OpticalCharacterRecognition } from "./nanonets/index.js";

const apiKey = "";
const modelId = "";
const urlArray = ["", ""];
const startInterval = 18917;
const endInterval = 18919;
const fileId = "";

const ocr = new OpticalCharacterRecognition(apiKey, modelId);

console.log(await ocr.getModelDetails());
console.log(await ocr.getAllPredictedFileData(startInterval, endInterval));
console.log(await ocr.getPredictedFileDataById(fileId));
console.log(await ocr.predictUsingUrls(urlArray));
console.log(await ocr.predictUsingUrlsAsync(urlArray));
```
Empty file added index.cjs
Empty file.
107 changes: 107 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import fetch from "node-fetch";

if (!globalThis.fetch) {
globalThis.fetch = fetch;
}

export class OpticalCharacterRecognition {
constructor(apiKey, modelId) {
this.apiKey = apiKey;
this.modelId = modelId;
this.authHeaderVal =
"Basic " + Buffer.from(`${this.apiKey}:`).toString("base64");
}

async getModelDetails() {
const response = await fetch(
`https://app.nanonets.com/api/v2/OCR/Model/${this.modelId}`,
{
headers: {
"Authorization": this.authHeaderVal,
"Accept": "application/json"
}
}
);
const data = response.json();

return data;
}

async getAllPredictedFileData(startInterval, endInterval) {
const response = await fetch(
`https://app.nanonets.com/api/v2/Inferences/Model/${this.modelId}/ImageLevelInferences/?start_day_interval=${startInterval}&current_batch_day=${endInterval}`,
{
headers: {
"Authorization": this.authHeaderVal,
"Accept": "application/json"
}
}
);
const data = response.json();

return data;
}

async getPredictedFileDataById(fileId) {
const response = await fetch(
`https://app.nanonets.com/api/v2/Inferences/Model/${this.modelId}/ImageLevelInferences/${fileId}`,
{
headers: {
"Authorization": this.authHeaderVal,
"Accept": "application/json"
}
}
);
const data = response.json();

return data;
}

async predictUsingUrls(urlArray) {
let encodedUrls = new URLSearchParams();
for (let i = 0; i < urlArray.length; i++) {
encodedUrls.append("urls", urlArray[i]);
}
encodedUrls = encodedUrls.toString();

const response = await fetch(
`https://app.nanonets.com/api/v2/OCR/Model/${this.modelId}/LabelUrls`,
{
method: "POST",
headers: {
"Authorization": this.authHeaderVal,
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json"
},
body: encodedUrls
}
);
const data = response.json();

return data;
}

async predictUsingUrlsAsync(urlArray) {
let encodedUrls = new URLSearchParams();
for (let i = 0; i < urlArray.length; i++) {
encodedUrls.append("urls", urlArray[i]);
}
encodedUrls = encodedUrls.toString();

const response = await fetch(
`https://app.nanonets.com/api/v2/OCR/Model/${this.modelId}/LabelUrls/?async=true`,
{
method: "POST",
headers: {
"Authorization": this.authHeaderVal,
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json"
},
body: encodedUrls
}
);
const data = response.json();

return data;
}
}
97 changes: 97 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "nanonets",
"version": "0.0.1",
"description": "NanoNets' Optical Character Recognition and Image Classification Node.js SDK.",
"main": "index.js",
"exports": {
"import": "./index.js",
"require": "./index.cjs",
"default": "./index.js"
},
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/HarshKapadia2/nanonets.git"
},
"keywords": [
"nanonets",
"sdk",
"ocr",
"image-classification",
"nodejs"
],
"author": "Harsh Kapadia <harshgkapadia@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/HarshKapadia2/nanonets/issues"
},
"homepage": "https://github.com/HarshKapadia2/nanonets#readme",
"dependencies": {
"node-fetch": "^3.0.0"
}
}

0 comments on commit e6bb49b

Please sign in to comment.