Using trained model

There are two main options to use your model: via SentiSight.ai web platform or via REST API. If you would like to download and use the model locally, it might also be arranged as a Custom project.

Using trained model via SentiSight.ai web platform

To start using your trained model press "Explore models/predict" -> Select model -> Make a new prediction and select images to upload from your PC.

You will see the results on the browser screen. Also, there are two options to download the results:

  • In .json format
  • As a .zip file with images grouped into folders by the predicted label

Using REST API by uploading image file

To begin using REST API you will need these details:
  • API token (available under "User profile" menu tab)
  • Project ID (available under "User profile" menu tab)
  • Model name (shown in many places, for example, under "Explore models/predict" menu)

Also, you will need an image file for which you want to make the prediction.

For image classification use this endpoint: https://tool.sentisight.ai/api/predict/{your_project_id}/{your_model_name}/

Set the "X-Auth-token" header to your API token string and set "Content-Type" header to "application/octet-stream". Set the body to your image file.

For more details, see the code samples below.


import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.nio.file.Files;

public class App
{
   public static void main( String[] args ) throws IOException
   {
       if (args.length < 4) {
           System.out.println("Usage: java -jar sample.jar api_token project_id model_name file");
       }
       String token = args[0];
       String projectId = args[1];
       String modelName = args[2];
       String imageFilename = args[3];
       
       byte[] bytes = Files.readAllBytes(new File(imageFilename).toPath());
       
       URL url = new URL("https://tool.sentisight.ai/api/predict/" + projectId + "/" + modelName);
       HttpURLConnection connection = (HttpURLConnection)url.openConnection();        
       connection.setRequestProperty("Content-Type", "application/octet-stream");
       connection.setRequestProperty("X-Auth-token", token);
       connection.setRequestMethod("POST");
       connection.setDoOutput(true);
       DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
        wr.write(bytes);
        wr.flush();
        wr.close();
        
        BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        String output;
        StringBuffer response = new StringBuffer();

        while ((output = in.readLine()) != null) {
            System.out.println(output);
            response.append(output);
        }
        in.close();
   }
}



	
		
		Sample%MINIFYHTMLd63c84751a31bc4c5fa12367d93466924%
	
		Token: 
		
Project id:
Model name:
Upload image:

%MINIFYHTMLd63c84751a31bc4c5fa12367d93466925%

import requests

token = "your_token"
project_id = "your_project_id"
model = "your_model_name"
image_filename = "your_image_path"

headers = {"X-Auth-token": token, "Content-Type": "application/octet-stream"}

with open(image_filename, 'rb') as handle:
    r = requests.post('https://tool.sentisight.ai/api/predict/{}/{}/'.format(project_id,model), headers=headers, data=handle)

if r.status_code == 200:
    print(r.text)
else:
    print('Error occured with REST API.')
    print('Status code: {}'.format(r.status_code))
    print('Error message: ' + r.text)

Using REST API with image url

Using the REST API by providing an image url is very similar to the previous case of using REST API by uploading the image. The only differences are that you need to set "Content-Type" header to "text/plain" and set the body to your image url.

For more details, see the code samples below.

package sentisight.api.predict.sample;

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class App
{
   public static void main( String[] args ) throws IOException
   {
       if (args.length < 4) {
           System.out.println("Usage: java -jar sample.jar api_token project_id model_name url");
       }
       String token = args[0];
       String projectId = args[1];
       String modelName = args[2];
       String image_url = args[3];
       
       URL url = new URL("https://tool.sentisight.ai/api/predict/" + projectId + "/" + modelName);
       HttpURLConnection connection = (HttpURLConnection)url.openConnection();        
       connection.setRequestProperty("Content-Type", "text/plain");
       connection.setRequestProperty("X-Auth-token", token);
       connection.setRequestMethod("POST");
       connection.setDoOutput(true);
       DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
        wr.writeBytes(image_url);
        wr.flush();
        wr.close();
        
        BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        String output;
        StringBuffer response = new StringBuffer();

        while ((output = in.readLine()) != null) {
            System.out.println(output);
            response.append(output);
        }
        System.out.println(connection.getResponseCode());
        in.close();
   }
}



	
		
		Sample%MINIFYHTMLd63c84751a31bc4c5fa12367d93466926%
	
		Token: 
		
Project id:
Model name:
Url:

import requests

token = "your_token"
project_id = "your_project_id"
model = "your_model_name"
image_url = "http://your-image-url.png"

headers = {"X-Auth-token": token, "Content-Type": "text/plain"}

r = requests.post('https://tool.sentisight.ai/api/predict/{}/{}/'.format(project_id,model), headers=headers, data = image_url)

if r.status_code == 200:
    print(r.text)
else:
    print('Error occured with REST API.')
    print('Status code: {}'.format(r.status_code))
    print('Error message: ' + r.text)