GithubHelp home page GithubHelp logo

classicvalues / deepai-js-client Goto Github PK

View Code? Open in Web Editor NEW

This project forked from deepai-org/deepai-js-client

1.0 1.0 0.0 4.29 MB

Simple Javascript Client Library for Browser and Node.js for calling DeepAI's APIs

Home Page: https://deepai.org

License: BSD 2-Clause "Simplified" License

JavaScript 100.00%

deepai-js-client's Introduction

DeepAI JS Client

npm version

Simple Javascript Client Library for Deep AI's APIs from Browser and Node.js

Installation:

Node.js or other environments using npm:

npm install --save deepai

Browser:

  • Option 1: (Recommended) Load the library from DeepAI's CDN:
    <script src="https://cdnjs.deepai.org/deepai.min.js"></script>
    
  • Option 2: Download and copy "dist/deepai.min.js" into your project and include in HTML
  • Option 3: include this npm package, use webpack or browserify, and "require('deepai'')"

Usage Examples:

Most examples are for Content Moderation, but you can subsitute any model name available at DeepAI.

Ensure that you pass the correct input names. Not all model input names are "image". You can find the correct input name on the page for each model at DeepAI.org

All examples use Async-Await syntax, so ensure you run the code in an async function.

Browser:

// Ensure you load deepai with one of the methods in "Installation"
deepai.setApiKey("YOUR_API_KEY"); // get your free API key at https://deepai.org

Pass URL:

var result = await deepai.callStandardApi("content-moderation", {
  image: "https://YOUR_IMAGE_URL",
});

Pass Literal Text:

var result = await deepai.callStandardApi("sentiment-analysis", {
  text: "I am very happy to play with the newest APIs!",
});

Pass Image DOM Element:

var result = await deepai.callStandardApi("content-moderation", {
  image: document.getElementById("yourImageId"),
});

Pass File Picker Element:

var result = await deepai.callStandardApi("content-moderation", {
  image: document.getElementById("yourFilePickerId"),
});
Browser Result Rendering

This code will render the result of the API call into an existing HTML element, such as a div, with the id "yourResultContainerId".

The result will fit itself inside your container, so be sure to set a size on it.

var result = await deepai.callStandardApi("content-moderation", {
  image: "https://YOUR_IMAGE_URL",
});

await deepai.renderResultIntoElement(
  result,
  document.getElementById("yourResultContainerId")
);
Rendering a result without an extra network request:

The function renderAnnotatedResultIntoElement is for advanced users only.

var resultAnnotated = {
    output_url: <Pass URL of the model output>
    output: <Pass the model output directly in case of JSON or text output>
    id: "fa616aa1-c762-4c98-b44e-75781627974a" <pass your job ID>
    inputs:[
        {
            is_img: true,
            url: (relative or absolute img url, annotations will be rendered on top of this result url.)
        }
    ],
    visualizer_data: {
        list_key: 'Objects', (Name of the list property containing annotations)
        label_key: 'Object' (Name of the value property to label annotations with)
    },
    scale_applied: 1.333 (Scale to multiply all detection x y coordinates by before rendering)
};

deepai.renderAnnotatedResultIntoElement(resultAnnotated, document.getElementById('yourResultContainerId'));

Node.js

const deepai = require("deepai");
deepai.setApiKey("YOUR_API_KEY"); // get your free API key at https://deepai.org

Pass URL:

var result = await deepai.callStandardApi("content-moderation", {
  image: "https://YOUR_IMAGE_URL",
});

Pass Literal Text:

var result = await deepai.callStandardApi("sentiment-analysis", {
  text: "I am very happy to play with the newest APIs!",
});

Pass File Upload:

const fs = require('fs');

<...>

var result = await deepai.callStandardApi("content-moderation", {
    image: fs.createReadStream('/path/to/your/file.jpg')
});

Build & publish this library (not required for users of this libary):

npm install
npm run-script build
npm login
npm publish

How the npm package works:

The webpack generated code (in dist/) is only used in the browser. The code in the lib folder is used in Node.js, although it would also work in the browser (for say, a React webpack app).

deepai-js-client's People

Contributors

dependabot[bot] avatar classicvalues avatar deepai-org avatar baragona avatar mend-bolt-for-github[bot] avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.