LogoLogo
  • What is Theos AI?
  • Get Started
    • Object Detection
    • Pose Estimation
  • Library
    • Computer Vision
      • Object Detection
      • Semantic Segmentation
      • Image Classification
      • Pose Estimation
      • Face Recognition
    • Natural Language Processing
      • Language Translation
      • Question Answering
      • Sentiment Analysis
      • Text Generation
      • Text Summarization
    • Speech
      • Speech Recognition
      • Voice Cloning
      • Emotion Recognition
      • Speaker Verification
      • Speech Synthesis
  • Datasets
    • Image
      • Upload
      • Classes
      • Labels
        • Bounding Box
          • Labeling
          • Autolabeling
          • Formats
            • Theos JSON
            • COCO JSON
            • Darknet TXT
            • Pascal VOC
    • Text
    • Audio
  • Machines
    • Theos Cloud
    • Google Colab
    • On-Premise
  • Train
  • Deploy
    • OCR Languages
  • Rest API
    • Datasets
    • Machines
    • Train
    • Deploy
Powered by GitBook
On this page
  • Overview
  • Create a new deployment
  • Configure your deployment
  • Deploy your AI
  • Try out your AI inside the playground
  • Use your AI in your software

Was this helpful?

Deploy

Deploy your AI into production on a highly scalable REST API entirely managed by Theos.

PreviousTrainNextOCR Languages

Last updated 2 years ago

Was this helpful?

Overview

Deploy is the fifth section of the platform. Here you can deploy your AI into a highly scalable REST API entirely managed by Theos, so you can finally use it in your software.

Create a new deployment

Configure your deployment

Choose the algorithm

Choose the algorithm version you used to train your AI.

Choose the weights

Choose which weights you want your AI to use.

Deploy your AI

Click the Finish button to deploy your AI to a highly scalable REST API. Your AI should be deployed within a few minutes.

Try out your AI inside the playground

Drag and drop an image to Theos and click the Detect button to try your AI.

Use your AI in your software

The request has 6 possible fields:

  • image (required): the binary data of an image or video frame.

  • conf_thres (optional): is the Minimum confidence value configurable in the Playground, possible values go from 0 to 1.

  • iou_thres (optional): is the Detection recall value configurable in the Playground, possible values go from 0 to 1.

  • ocr_model (optional): is the Text Recognition Model value configurable in the Playground, possible values are small, medium or large.

  • ocr_classes (optional): the class names on which to perform OCR on, they are comma separated. For example: license-plate, billboard, signature.

Terminal

For Linux and MacOS.

curl PASTE_YOUR_URL_HERE \
     -F "image=@image.jpg" \
     -F "conf_thres=0.25" \
     -F "iou_thres=0.45" \
     -X POST

For Windows.

curl PASTE_YOUR_URL_HERE ^
     -F "image=@image.jpg" ^
     -F "conf_thres=0.25" ^
     -F "iou_thres=0.45" ^
     -X POST

Python

We will use the requests package to make HTTP post requests.

pip install requests

Add the following code to your software to send an image to your AI and receive back its detections.

import requests
import json
import time

URL = '' # copy and paste your URL here
FALLBACK_URL = '' # copy and paste your fallback URL here
IMAGE_PATH = './image.jpg'

def detect(image_path, url=URL, conf_thres=0.25, iou_thres=0.45, ocr_model=None, ocr_classes=None, ocr_language=None, retries=10, delay=0):
    response = requests.post(url, data={'conf_thres':conf_thres, 'iou_thres':iou_thres, **({'ocr_model':ocr_model, 'ocr_classes':ocr_classes, 'ocr_language':ocr_language} if ocr_model is not None else {})}, files={'image':open(image_path, 'rb')})
    if response.status_code in [200, 500]:
        data = response.json()
        if 'error' in data:
            print('[!]', data['message'])
        else:
            return data
    elif response.status_code == 403:
        print('[!] you reached your monthly requests limit. Upgrade your plan to unlock unlimited requests.')
    elif retries > 0:
        if delay > 0:
            time.sleep(delay)
        return detect(image_path, url=FALLBACK_URL if FALLBACK_URL else URL, retries=retries-1, delay=2)
    return []

detections = detect(IMAGE_PATH)

if len(detections) > 0:
    print(json.dumps(detections, indent=2))
else:
    print('no objects found.')

React

We will use the axios package to make HTTP post requests.

npm install axios

Finally, create the following component and import it in your app to send an image to your AI and receive back its detections.

import React, { useState } from 'react';
import axios from 'axios';

const URL = ''; // copy and paste your URL here
const FALLBACK_URL = ''; // copy and paste your fallback URL here

function sleep(seconds) {
  return new Promise((resolve) => setTimeout(resolve, seconds * 1000));
}

async function detect({imageFile, url=URL, confThres=0.25, iouThres=0.45, ocrModel=undefined, ocrClasses=undefined, ocrLanguage=undefined, retries=10, delay=0}={}) {
  const data = new FormData();
  data.append('image', imageFile);
  data.append('conf_thres', confThres);
  data.append('iou_thres', iouThres);
  if(ocrModel !== undefined){
    data.append('ocr_model', ocrModel);  
  }
  if(ocrClasses !== undefined){
    data.append('ocr_classes', ocrClasses);  
  }
  if(ocrLanguage !== undefined){
    data.append('ocr_language', ocrLanguage);  
  }
  try {
    const response = await axios({ method: 'post', url: url, data: data, headers:{'Content-Type':'multipart/form-data'}});
    return response.data;
  } catch (error) {
    if (error.response) {
      if(error.response.status === 0 || error.response.status === 413) throw new Error('image too large, please select an image smaller than 25MB.');
      else if(error.response.status === 403) throw new Error('you reached your monthly requests limit. Upgrade your plan to unlock unlimited requests.');
      else if(error.response.data) throw new Error(error.response.data.message);
    } else if (retries > 0) {
      if (delay > 0) await sleep(delay);
      return await detect(imageFile, url= FALLBACK_URL ? FALLBACK_URL : URL, confThres=0.25, iouThres=0.45, retries=retries-1, delay=2);
    } else {
      return [];
    }
  }
}

function TheosAPI() {
  const [detecting, setDetecting] = useState(false);
  const [detected, setDetected] = useState(false);
  const [detections, setDetections] = useState('');
  const [error, setError] = useState('');

  function onFileSelected(event) {
    const file = event.target.files[0];
    setDetecting(true);
    setDetected(false);
    setDetections([]);
    setError('');
    detect({imageFile:file})
      .then(detections => {
        setDetected(true);
        setDetecting(false);
        setDetections(detections.length > 0? `${detections.length} OBJECTS FOUND\n${detections.map((detection, index) => ` ${'_'.repeat(30)}\n|\n| ${index+1}. ${detection.class}\n|\n|${'‾'.repeat(30)}\n|  ‣ confidence: ${detection.confidence*100}%\n|  ‣ x: ${detection.x}\n|  ‣ y: ${detection.y}\n|  ‣ width: ${detection.width}\n|  ‣ height: ${detection.height}\n|${'text' in detection? '  ‣ text: ' + detection.text:''}\n ${'‾'.repeat(30)}\n`).join('')}`: 'No objects found.');
      })
      .catch(error => {
        setError(error.message);
        setDetecting(false);
      });
  }

  return (
    <div style={{ padding: '20px' }}>
      <h1>Theos API</h1>
      {detecting ? <h3>Detecting...</h3> : <div><label htmlFor='file-upload' style={{cursor:'pointer', display:'inline-block', padding:'8px 12px', borderRadius: '5px', border:'1px solid #ccc'}}>Click to select an image</label><input id='file-upload' type='file' accept='image/*' onChange={onFileSelected} style={{display:'none'}}/></div>}
      {detected && <h3><pre>{detections}</pre></h3>}
      {error && <h3 style={{color:'red'}}>{error}</h3>}
    </div>
  );
}

export default TheosAPI;

Go to the section of Theos and click the New deployment button to deploy your AI into a highly scalable REST API. Write a name for your deployment and click confirm.

Start using your AI in your software by making simple HTTP post requests to your deployment's URL. If you have one of our , in addition to having 2x faster response times and no cold starts, you will also have a Fallback URL that you must include to ensure 99.999% up time.

ocr_language (optional): if the ocr_model is small it is possible to set the target language for reading special characters of particular languages. If unspecified, the default language is English. See the to find your language of choice. Example for reading German: "ocr_language":"deu".

Deploy
professional plans
language code list
Deploy section
Creating a new deployment
Choosing the algorithm version
Choose the weights
Deployment of your AI
Detecting images inside the deployment's playground