Skip to content

Commit

Permalink
🚚 update: Remove Image Classification support
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshKapadia2 committed Nov 11, 2021
1 parent 3a81874 commit 5706a29
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 366 deletions.
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
example/
node_modules/
.prettierrc
.gitignore
.prettierignore
.prettierrc
106 changes: 23 additions & 83 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# nanonets
# NanoNets OCR Node.js SDK

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

> NOTE:
>
Expand All @@ -13,43 +13,35 @@ The [NanoNets](https://nanonets.com) Optical Character Recognition and Image Cla
## Installation

```
npm install nanonets
npm install @nanonets/optical-character-recognition
```

## Use the NanoNets SDK
## Use the NanoNets OCR SDK

> NOTE: A fully working example using the SDK can be found in the [example](example) directory.
1. Import/require the 'nanonets' package.
1. Import/require the OCR package.

```javascript
// ES Modules
import { OpticalCharacterRecognition, ImageClassification } from "nanonets";
import OpticalCharacterRecognition from "@nanonets/optical-character-recognition";

// CommonJS
const OpticalCharacterRecognition =
require("nanonets").OpticalCharacterRecognition;
const ImageClassification = require("nanonets").ImageClassification;
// OR
const {
OpticalCharacterRecognition,
ImageClassification
} = require("nanonets");
const OpticalCharacterRecognition = require("@nanonets/optical-character-recognition");
```

2. Instantiate the Optical Character Recognition (OCR) and/or Image Classification (IC) class.
2. Instantiate the Optical Character Recognition (OCR) class.

```javascript
const ocr = new OpticalCharacterRecognition(apiKey, modelId);
const ic = new ImageClassification(apiKey, modelId);
```

> NOTE:
>
> - The API Key can be found in the user's [NanoNets Account section](https://app.nanonets.com/#/keys) and Model ID can be found in the model's settings in the NanoNets web app.
> - Models need to be created and trained from [the NanoNets web app](https://app.nanonets.com) before being able to make predictions.
3. Use the [Optical Character Recognition API](#optical-character-recognition-api) and/or [Image Classification API](#image-classification-api) to get prediction results from the model(s).
3. Use the [Optical Character Recognition API](#optical-character-recognition-api) to get prediction results from the model(s).

## Optical Character Recognition API

Expand Down Expand Up @@ -91,6 +83,8 @@ const ocr = new OpticalCharacterRecognition(apiKey, modelId);
await ocr.getModelDetails();
```

[Response example and other details](https://nanonets.com/documentation/#operation/OCRModelGetAllPredictionFiles)

> The `getModelDetails` function returns a promise, so it needs to be awaited.
### Get All Predicted File Data
Expand All @@ -108,6 +102,8 @@ await ocr.getAllPredictedFileData(startInterval, endInterval);
- Type: Number (Integer)
- Required: True

[Response example and other details](https://nanonets.com/documentation/#operation/OCRModelListPredictionFiles)

> The `getAllPredictedFileData` function returns a promise, so it needs to be awaited.
### Get Predicted File Data
Expand All @@ -122,6 +118,8 @@ await ocr.getPredictedFileData(fileId);
- Type: String
- Required: True

[Response example and other details](https://nanonets.com/documentation/#operation/OCRModelGetPredictionFileById)

> The `getPredictedFileData` function returns a promise, so it needs to be awaited.
### Predict Using URLs
Expand All @@ -140,6 +138,11 @@ await ocr.predictUsingUrls(urlArray, isAsync);
- Required: False
- Default: False

#### Response Example and Other Details

- [Synchronous upload](https://nanonets.com/documentation/#operation/OCRModelLabelUrlsByModelIdPost)
- [Asynchronous upload](https://nanonets.com/documentation/#operation/OCRModelLabelUrlsAsyncByModelIdPost)

> The `predictUsingUrls` function returns a promise, so it needs to be awaited.
### Predict Using File
Expand All @@ -158,72 +161,9 @@ await ocr.predictUsingFile(filePath, isAsync);
- Required: False
- Default: False

> The `predictUsingFile` function returns a promise, so it needs to be awaited.
## Image Classification API

### Table of Contents

- [Class Instantiation (Constructor)](#class-instantiation-constructor-1)
- [Get Model Details](#get-model-details-1)
- [Predict Using URLs](#predict-using-urls-1)
- [Predict Using File](#predict-using-file-1)

### Class Instantiation (Constructor)

```javascript
const ic = new ImageClassification(apiKey, modelId);
```

#### Parameters

- `apiKey`
- Type: String
- Required: True
- `modelId`
- Type: String
- Required: True

> NOTE:
>
> - Class Instantiation is mandatory.
> - The API Key can be found in the user's [NanoNets Account section](https://app.nanonets.com/#/keys) and Model ID can be found in the model's settings in the NanoNets web app.
> - API Keys have full access to the user's account. **Please do not expose API Keys on the client.**
> - Please note that compiling, obfuscating, minifying or bundling (for example in React.js, Angular, Vue.js, React Native, etc.) **does not** hide the API Key and **it can still be extracted from the final application**.
> - The API Key should only be known to the server code and all client requests to the API must go through a server.
### Get Model Details

```javascript
await ic.getModelDetails();
```

> The `getModelDetails` function returns a promise, so it needs to be awaited.
### Predict Using URLs

```javascript
await ic.predictUsingUrls(urlArray);
```

#### Parameters
#### Response Example and Other Details

- `urlArray`
- Type: Array of Strings
- Required: True

> The `predictUsingUrls` function returns a promise, so it needs to be awaited.
### Predict Using File

```javascript
await ic.predictUsingFile(filePath);
```

#### Parameters

- `filePath`
- Type: String
- Required: True
- [Synchronous upload](https://nanonets.com/documentation/#operation/OCRModelLabelFileByModelIdPost)
- [Asynchronous upload](https://nanonets.com/documentation/#operation/OCRModelLabelFileAsyncByModelIdPost)

> The `predictUsingFile` function returns a promise, so it needs to be awaited.
4 changes: 2 additions & 2 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# NanoNets SDK Example
# NanoNets OCR SDK Example

A sample web app that uses the [NanoNets](https://nanonets.com) Optical Character Recognition and Image Classification Node.js SDK.
A sample web app that uses the [NanoNets](https://nanonets.com) Optical Character Recognition Node.js SDK.

## Usage Instructions

Expand Down
27 changes: 2 additions & 25 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import path from "path";
import { fileURLToPath } from "url";
import express from "express";
import multer from "multer";
import { ImageClassification, OpticalCharacterRecognition } from "../index.js";
import OpticalCharacterRecognition from "../index.js";
import dotenv from "dotenv";

// Server initialization
Expand All @@ -21,25 +21,18 @@ app.use("/public", express.static(__dirname + "/public"));
app.use(express.urlencoded({ extended: false }));
app.use(express.json());

// Class instantiations
// Class instantiation
// const ocr = new OpticalCharacterRecognition(
// process.env.API_KEY_1,
// process.env.MODEL_ID_1
// );
// const ic = new ImageClassification(
// process.env.API_KEY_1,
// process.env.MODEL_ID_2
// );

// Routes
app.get("/", async (req, res) => {
// const ocrUrlArray = [process.env.FILE_URL_1, process.env.FILE_URL_2];
// const icUrlArray = [process.env.FILE_URL_3, process.env.FILE_URL_4];
// const startInterval = 18917;
// const endInterval = 18919;

// Optical Character Recognition (OCR) functions

// console.log(
// await ocr.getModelDetails(),
// "\n-------------------------------------------------------\n"
Expand All @@ -61,17 +54,6 @@ app.get("/", async (req, res) => {
// "\n-------------------------------------------------------\n"
// );

// Image Classification (IC) functions

// console.log(
// await ic.getModelDetails(),
// "\n-------------------------------------------------------\n"
// );
// console.log(
// await ic.predictUsingUrls(icUrlArray),
// "\n-------------------------------------------------------\n"
// );

res.sendFile(__dirname + "/public/index.html");
});

Expand All @@ -92,11 +74,6 @@ app.post("/uploadFile", upload.single("file"), async (req, res) => {
await ocr.predictUsingFile(req.file.path, true),
"\n-------------------------------------------------------\n"
);
else if (req.body.operation === "ic")
console.log(
await ic.predictUsingFile(req.file.path),
"\n-------------------------------------------------------\n"
);

res.send("Uploaded. Check the server console for the response.");
});
Expand Down
4 changes: 2 additions & 2 deletions example/package-lock.json

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

15 changes: 7 additions & 8 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,28 @@
{
"name": "nanonets-sdk-example",
"name": "nanonets-ocr-sdk-example",
"version": "1.0.0",
"description": "An example using NanoNets' Node.js SDK.",
"description": "An example using NanoNets' OCR Node.js SDK.",
"main": "index.js",
"type": "module",
"scripts": {
"start": "nodemon index.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/HarshKapadia2/nanonets-sdk-example.git"
"url": "git+https://github.com/NanoNets/ocr-js-sdk.git"
},
"keywords": [
"nanonets",
"nodejs",
"sdk",
"ocr",
"image-classification"
"ocr"
],
"author": "Harsh Kapadia <harshgkapadia@gmail.com>",
"author": "NanoNets <support@nanonets.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/HarshKapadia2/nanonets-sdk-example/issues"
"url": "https://github.com/NanoNets/ocr-js-sdk/issues"
},
"homepage": "https://github.com/HarshKapadia2/nanonets-sdk-example#readme",
"homepage": "https://github.com/NanoNets/ocr-js-sdk#readme",
"dependencies": {
"dotenv": "^10.0.0",
"express": "^4.17.1",
Expand Down
12 changes: 4 additions & 8 deletions example/public/fileUpload.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@
}
</style>

<title>NanoNets Node.js SDK Example</title>
<title>NanoNets OCR Node.js SDK Example</title>
</head>

<body>
<h1>NanoNets Node.js SDK Example</h1>
<h2>Optical Character Recognition and Image Classification</h2>
<h3>File Upload Example</h3>
<h4>Check server console for output</h4>
<h1>NanoNets OCR Node.js SDK Example</h1>
<h2>File Upload Example</h2>
<h3>Check server console for output</h3>

<form action="/uploadFile" method="POST" enctype="multipart/form-data">
<p>Select operation</p>
Expand All @@ -54,9 +53,6 @@ <h4>Check server console for output</h4>
<label for="ocr-async"
>Optical Character Recognition (Asynchronous)</label
>
<br />
<input type="radio" id="ic" name="operation" value="ic" required />
<label for="ic">Image Classification</label>
<br /><br /><br />

<input
Expand Down
7 changes: 3 additions & 4 deletions example/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,12 @@
}
</style>

<title>NanoNets Node.js SDK Example</title>
<title>NanoNets OCR Node.js SDK Example</title>
</head>

<body>
<h1>NanoNets Node.js SDK Example</h1>
<h2>Optical Character Recognition and Image Classification</h2>
<h3>Check server console for output</h3>
<h1>NanoNets OCR Node.js SDK Example</h1>
<h2>Check server console for output</h2>

<a href="/uploadFile">File Upload Example</a>
</body>
Expand Down
3 changes: 0 additions & 3 deletions example/sample.env
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
API_KEY_1=
MODEL_ID_1=
MODEL_ID_2=
FILE_ID=
FILE_URL_1=
FILE_URL_2=
FILE_URL_3=
FILE_URL_4=
Loading

0 comments on commit 5706a29

Please sign in to comment.