Sensifai Python SDK for Image and Video Processing.
Project description
Sensifai API Python Client
Sensifai API Python Client
Overview
This Python client provides a wrapper around Sensifai [https://developer.sensifai.com](Image and Video recognition API).
Installation
The API client is available on Pip. You can simply install it with pip install
pip3 install sensifai -U
For more details on the installation, please refer to https://developer.sensifai.com/installation
Please always make sure that you'll use the latest version of our SDK.
Sample Usage
The following example will set up the client and predict video attributes. First of all, you need to import the library and define an instance from SensifaiApi class using SENSIFAI_API_TOKEN. You can get a free limited token from https://developer.sensifai.com by creating an application.
from sensifai import SensifaiApi
first of all, create an instance of SensifaiApi
token = 'Your_token_that_you_create_in_panel'
sensifai_api = SensifaiApi(token = token)
after that, call upload_by_files or upload_by_urls with appropriate list. let's see an example:
# url example for image urls
urls_list = ['https://url1.png', 'http://url2.jpg']
# url example for video urls
# urls_list = ['https://url1.avi', 'http://url2.mp4']
task_dict = sensifai_api.upload_by_urls(urls_list)
# file example
files_list = ['/home/user/1.png', '/var/file/video.jpg']
task_dict = sensifai_api.upload_by_files(files_list)
as you can see, upload_by_files and upload_by_urls return a variable that is a dictionary contain succeed that a list of dictionaries with file and taskId and cannotUpload that are links that cannot upload list contain the links that the server failed to get them or conflict with the token. for example, if you set a video token for an instance and send image with it, they won't be processed and return cannot upload list.
at the end, to retrieve result of a task, pass it through get_result . Please don't remember to pass a single task id! this function won't work with a list of task id.
results = sensifai_api.get_result(task_id)
Notice: result type is dictionary. there are two variables that always present in the result, isDone, and errors. the first one defines the state of a task. if all selected services are ready, isDone will be true, otherwise it will be false if the task id belongs to an image, you'll get imageResults in your dictionary and for video, you'll get videoResults.
if task id belongs to a video, you'll get fps, duration, and framesCount too. imageResults is a dictionary of selected service results that you choose when you're creating the application. videoResults is a list of shots that every shot is a dictionary contains startSecond, endSecond, startFrame, endFrame, thumbnailPath and selected service result that you choose when you're creating the token.
Here's how to save all the predicted concepts associated with the video.
import json
from pprint import pprint
for id in task_dict["succeed"]:
result = sensifai_api.get_result(id["taskId"])
pprint(id["file"])
JSON_FILE_PATH="/home/foo/{}-result.json".format(id["file"])
json.dump(result,open(JSON_FILE_PATH,'w'))
pprint(result)
pprint("_____________________________")
#To save as a JSON file
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file Sensifai-0.6.1.tar.gz.
File metadata
- Download URL: Sensifai-0.6.1.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.49.0 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ba6a96f1f9ffdfb983701b1650edf2971289cc4e76406cc346f078366fbbea26
|
|
| MD5 |
8d28bc493f19f0fddbae62ba98ae1793
|
|
| BLAKE2b-256 |
18b41ce7bdc5808061cedae54b96774bf26ed715de5fd8f88d9ac5e32971e43c
|