Socket
Socket
Sign inDemoInstall

roboflow

Package Overview
Dependencies
Maintainers
8
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

roboflow - npm Package Compare versions

Comparing version 0.0.4 to 0.0.5

cli/commands/inference.js

87

api.js

@@ -61,2 +61,83 @@ const config = require("./config.js");

async function detectObject(filepath, modelUrl, apiKey, options) {
const image = fs.readFileSync(filepath, {
encoding: "base64"
});
const response = await axios({
method: "POST",
url: `${config.get("RF_OBJECT_DETECTION_URL")}/${modelUrl}`,
params: {
api_key: apiKey,
...options
},
data: image,
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
});
return response.data;
}
async function classify(filepath, modelUrl, apiKey) {
const image = fs.readFileSync(filepath, {
encoding: "base64"
});
const response = await axios({
method: "POST",
url: `${config.get("RF_CLASSIFICATION_URL")}/${modelUrl}`,
params: {
api_key: apiKey
},
data: image,
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
});
return response.data;
}
async function instanceSegmentation(filepath, modelUrl, apiKey) {
const image = fs.readFileSync(filepath, {
encoding: "base64"
});
const response = await axios({
method: "POST",
url: `${config.get("RF_INSTANCE_SEGMENTATION_URL")}/${modelUrl}`,
params: {
api_key: apiKey
},
data: image,
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
});
return response.data;
}
async function semanticSegmentation(filepath, modelUrl, apiKey) {
const image = fs.readFileSync(filepath, {
encoding: "base64"
});
const response = await axios({
method: "POST",
url: `${config.get("RF_SEMANTIC_SEGMENTATION_URL")}/${modelUrl}`,
params: {
api_key: apiKey
},
data: image,
headers: {
"Content-Type": "application/x-www-form-urlencoded"
}
});
return response.data;
}
module.exports = api = {

@@ -67,3 +148,7 @@ getWorkspace,

getFormat,
uploadImage
uploadImage,
detectObject,
classify,
instanceSegmentation,
semanticSegmentation
};

10

cli/commands/auth.js

@@ -6,7 +6,7 @@ const open = require("open");

const conf = require("../../config.js");
const config = require("../../config.js");
const selectDefaultWorkspace = require("./selectDefaultWorkspace.js");
module.exports = async function auth() {
const authUrl = `${conf.get("RF_APP_URL")}/auth-cli`;
const authUrl = `${config.get("RF_APP_URL")}/auth-cli`;

@@ -42,10 +42,10 @@ try {

const cli_auth_token = token_input.cli_auth_token;
console.log("GET", `${conf.get("RF_APP_URL")}/query/cliAuthToken/${cli_auth_token}`);
console.log("GET", `${config.get("RF_APP_URL")}/query/cliAuthToken/${cli_auth_token}`);
const authDataResponse = await axios.get(
`${conf.get("RF_APP_URL")}/query/cliAuthToken/${cli_auth_token}`
`${config.get("RF_APP_URL")}/query/cliAuthToken/${cli_auth_token}`
);
const authData = authDataResponse.data;
conf.set("workspaces", authData);
config.set("workspaces", authData);
await selectDefaultWorkspace();
};

@@ -1,7 +0,7 @@

const conf = require("../../config.js");
const config = require("../../config.js");
const chalk = require("chalk");
module.exports = async function listWorkspaces() {
const workspaces = conf.get("workspaces");
const defaultWorkspaceUrl = conf.get("RF_WORKSPACE");
const workspaces = config.get("workspaces");
const defaultWorkspaceUrl = config.get("RF_WORKSPACE");

@@ -8,0 +8,0 @@ if (!workspaces) {

@@ -1,2 +0,2 @@

const conf = require("../../config.js");
const config = require("../../config.js");
const chalk = require("chalk");

@@ -7,5 +7,5 @@

module.exports = async function printConfig(options) {
log(chalk.green(`Config file is stored at: ${chalk.bold(conf.path)}`));
log(chalk.green(`Config file is stored at: ${chalk.bold(config.configFile)}`));
log(`config values:`);
log({ ...conf.store });
log({ ...config.getAll() });
};
const open = require("open");
const conf = require("../../config.js");
const config = require("../../config.js");
const chalk = require("chalk");
module.exports = async function reset() {
conf.clear();
config.clear();
console.log(chalk.red("all data reset"));
};

@@ -1,2 +0,2 @@

const conf = require("../../config.js");
const config = require("../../config.js");
const chalk = require("chalk");

@@ -10,3 +10,3 @@

console.log("select default 1", newDefaultWorkspace);
conf.set("RF_WORKSPACE", newDefaultWorkspace);
config.set("RF_WORKSPACE", newDefaultWorkspace);
};
const fs = require("fs");
const path = require("path");
const conf = require("../../config.js");

@@ -5,0 +4,0 @@ const { selectProjectFromWorkspace, getApiKeyWorWorkspace } = require("../core.js");

const chalk = require("chalk");
const enquirer = require("enquirer");
const conf = require("../config.js");
const config = require("../config.js");

@@ -8,3 +8,3 @@ const { getWorkspace } = require("../api.js");

function getApiKeyWorWorkspace(workspaceId) {
const workspaces = conf.get("workspaces");
const workspaces = config.get("workspaces");

@@ -35,3 +35,3 @@ if (!workspaces) {

async function selectWorkspace() {
const workspaces = conf.get("workspaces");
const workspaces = config.get("workspaces");

@@ -38,0 +38,0 @@ if (!workspaces) {

@@ -14,9 +14,10 @@ #! /usr/bin/env node

const conf = require("../config.js");
const inference = require("./commands/inference.js");
const config = require("../config.js");
global.debug = false;
async function main() {
const defaultWorkspace = await conf.get("default_workspace");
// const defaultProject = await conf.get("default_project");
const defaultWorkspace = await config.get("RF_WORKSPACE");

@@ -27,2 +28,4 @@ const program = new Command();

program.addHelpText("before", `\nroboflow cli: computer vision at your fingertips 🪄\n`);
program.option("-d, --debug", "print verbose debugging info").on("option:debug", function () {

@@ -43,2 +46,71 @@ console.log("enabling debug logging");

program
.command("detect")
.description("perform object detection inference on an image")
.requiredOption(
"-m --model <model>",
"model id (id of a version with trained model e.g. my-project/3)"
)
.option(
"-c --confidence [threshold]",
"specify a confidence threshold between 0.0 and 1.0, default is 0.5"
)
.option(
"-o --overlap [threshold]",
"specify an overlap threshold between 0.0 and 1.0, default is 0.5",
0.5
)
.option(
"-w --workspace [workspace]",
"specify a workspace url or id (will use default workspace if not specified)",
defaultWorkspace
)
.argument("<file>", "filesystem path to an image file")
.action(inference.detectObject);
program
.command("classify")
.description("perform classification on an image")
.requiredOption(
"-m --model <model>",
"model id (id of a version with trained model e.g. my-project/3)"
)
.option(
"-w --workspace [workspace]",
"specify a workspace url or id (will use default workspace if not specified)",
defaultWorkspace
)
.argument("<file>", "filesystem path to an image file")
.action(inference.classify);
program
.command("instance-segmentation")
.description("perform instance segmentation on an image")
.requiredOption(
"-m --model <model>",
"model id (id of a version with trained model e.g. my-project/3)"
)
.option(
"-w --workspace [workspace]",
"specify a workspace url or id (will use default workspace if not specified)",
defaultWorkspace
)
.argument("<file>", "filesystem path to an image file")
.action(inference.instanceSegmentation);
program
.command("semantic-segmentation")
.description("perform semantic segmentation on an image")
.requiredOption(
"-m --model <model>",
"model id (id of a version with trained model e.g. my-project/3)"
)
.option(
"-w --workspace [workspace]",
"specify a workspace url or id (will use default workspace if not specified)",
defaultWorkspace
)
.argument("<file>", "filesystem path to an image file")
.action(inference.semanticSegmentation);
program
.command("upload")

@@ -45,0 +117,0 @@ .description("upload a file to your project")

const Conf = require("conf");
const RF_CLI_ENV = process.env.RF_CLI_ENV;
const config = new Conf({
projectSuffix: "",
cwd: process.env.HOME + "/.config/roboflow",
projectName: "roboflow"
});
let conf;
const DEFAULTS = {
RF_APP_URL: "https://app.roboflow.com",
RF_API_URL: "https://api.roboflow.com"
};
if (!RF_CLI_ENV) {
conf = new Conf({
projectSuffix: "",
cwd: process.env.HOME + "/.config/roboflow",
projectName: "roboflow",
defaults: { RF_APP_URL: "https://app.roboflow.com", RF_API_URL: "https://api.roboflow.com" }
});
} else {
conf = new Conf({
projectSuffix: RF_CLI_ENV,
cwd: process.env.HOME + "/.config/roboflow",
defaults: {
RF_APP_URL: process.env.RF_APP_URL,
RF_API_URL: process.env.RF_API_URL
}
});
// env vars take precedence over config values
function getCascadingConfigValue(key, defaultValue) {
if (key.startsWith("RF_") && process.env[key]) {
return process.env[key];
} else if (config.has(key)) {
return config.get(key);
} else {
return DEFAULTS[key];
}
}
module.exports = conf;
module.exports = {
get: function (key) {
return getCascadingConfigValue(key);
},
set(key, value) {
return config.set(key, value);
},
getAll() {
return {
...config.store,
RF_WORKSPACE: getCascadingConfigValue("RF_WORKSPACE"),
RF_APP_URL: getCascadingConfigValue("RF_APP_URL"),
RF_API_URL: getCascadingConfigValue("RF_API_URL"),
RF_OBJECT_DETECTION_URL: getCascadingConfigValue(
"RF_OBJECT_DETECTION_URL",
"https://detect.roboflow.com"
),
RF_CLASSIFICATION_URL: getCascadingConfigValue(
"RF_CLASSIFICATION_URL",
"https://classify.roboflow.com"
),
RF_INSTANCE_SEGMENTATION_URL: getCascadingConfigValue(
"RF_INSTANCE_SEGMENTATION_URL",
"https://outline.roboflow.com"
),
RF_SEMANTIC_SEGMENTATION_URL: getCascadingConfigValue(
"RF_SEMANTIC_SEGMENTATION_URL",
"https://segment.roboflow.com"
)
};
},
clear() {
return config.clear();
},
configFile: config.path
};
{
"name": "roboflow",
"version": "0.0.4",
"version": "0.0.5",
"description": "Roboflow.ai node module and CLI tools",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -5,1 +5,51 @@ # Roboflow node library

[https://roboflow.ai](https://roboflow.ai)
## Node Module
## CLI tool
This package install a `roboflow` CLI you can use from your terminal.
To install this package and CLI globally:
```
npm i -g roboflow
```
### Authorize the CLI
To authotize your CLI, run the following command.
```
roboflow auth
```
This will open a browser window and have you log into roboflow where you can select any workspaces you want the CLI to store auth credentials for (The CLi will download the api keys for the workspaces and store them in a config fle in the `~/.config/roboflow` directory on your system).
### Using the CLI
You can use the `roboflow` CLI to:
- list your workspaces
- select a default workspace to use
- list your projects
- upload images to your projects
- use it to get inference results for local images (for any of your object detection, classification, or segmentation models)
For more info on how to use the CLI see the help an usage instructions by running:
```
roboflow -h
```
You can also get specific help for each of the available sucommands, like e.g.:
```
roboflow upload -h
```
or
```
roboflow detect -h
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc