# Image Sentiment

## Overview

Image Sentiment is one of the intelligence services of the Filestack platform. You can detect general emotions of the uploaded images.

## Processing API

Image Sentiment is available as a synchronous operation in the Processing API using the following task:

`image_sentiment`

To use this task in Processing API, you have to use security policy and signature. Read more about security policies [here](https://www.filestack.com/docs/security/policies/).

### Response

Input image:

_Photo by [Candice Picard](https://unsplash.com/@candice_picard?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText) on [Unsplash](https://unsplash.com/?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText)_

```
{
    "emotions": {
        "HAPPY": 99.74745178222656,
        "FEAR": 0.09662599116563797,
        "SAD": 0.04409734904766083,
        "ANGRY": 0.039630014449357986,
        "SURPRISED": 0.03320338949561119,
        "DISGUSTED": 0.013468324206769466,
        "CONFUSED": 0.01307707466185093,
        "CALM": 0.012453563511371613
    }
}
```

- If no emotional content was detected:

```
{
"emotions": {
}
}
```

### Response Parameters

|     |     |     |
| --- | --- | --- |
| **emotions** | [dictionary](https://www.filestack.com/docs/transformations/intelligence/image-sentiment/#color-options) | Contains detected emotions |

### Examples

- Get the sentiment of your uploaded file:

```
https://cdn.filestackcontent.com/security=p:<POLICY>,s:<SIGNATURE>/image_sentiment/<HANDLE>
```

- Use image_sentiment in a chain with other tasks such as tagging:

```
https://cdn.filestackcontent.com/security=p:<POLICY>,s:<SIGNATURE>/tags/image_sentiment/<HANDLE>
```

- Use image_sentiment with an external URL:

```
https://cdn.filestackcontent.com/<FILESTACK_API_KEY>/security=p:<POLICY>,s:<SIGNATURE>/image_sentiment/<EXTERNAL_URL>
```

- Use image_sentiment with [Storage Aliases](https://www.filestack.com/docs/delivery/storage_aliases/):

```
https://cdn.filestackcontent.com/<FILESTACK_API_KEY>/security=p:<POLICY>,s:<SIGNATURE>/image_sentiment/src://<STORAGE_ALIAS>/<PATH_TO_FILE>
```

## Workflows Task Configuration

In order to learn how you can use Workflows UI to configure tasks and logic items, please visit [Creating Workflows Tutorial](https://www.filestack.com/docs/tutorials/create-workflow/).

Image Sentiment task is available in [Intelligence](https://www.filestack.com/docs/workflows/overview/#tasks) tasks category.

### Workflows Parameters

|     |     |     |
| --- | --- | --- |
| **Task Name** | [string](https://www.filestack.com/docs/transformations/intelligence/image-sentiment/#color-options) | Unique name of the task which will be included in the webhook response and can be used to build [logic](https://www.filestack.com/docs/transformations/intelligence/image-sentiment/#logic) below. |

## Logic

Image Sentiment task returns following response to the workflow:

```
{
  "data": {
    "emotions": {
        "HAPPY": 99.25,
        "SURPRISED": 0.40,
        "CALM": 0.18,
        "CONFUSED": 0.05,
        "ANGRY": 0.04,
        "SAD": 0.03,
        "FEAR": 0.01,
        "DISGUSTED": 0.01
    }
  }
}
```

or

```
{
  "data": {
    "emotions": {
    }
  }
}
```

### Logic Parameters

|     |     |     |
| --- | --- | --- |
| **data** | [dictionary](https://www.filestack.com/docs/transformations/intelligence/image-sentiment/#color-options) | Includes the information of image sentiment task. |
| **emotions** | [dictionary](https://www.filestack.com/docs/transformations/intelligence/image-sentiment/#color-options) | Contains detected emotions. |

Considering the response from the task, you can build [logic](https://www.filestack.com/docs/workflows/overview/#logic) in order to make independent flows with different executing tasks. For example, if you would like to run another depending on the happiness level detected, you can use the following rule:

`emotions.HAPPY gt 90.0` or `emotions.HAPPY lt 10.0`

In Workflows UI this command would be similar to the example below:

Visit [Creating Workflows Tutorial](https://www.filestack.com/docs/tutorials/create-workflow/) to learn how you can use Workflows UI to configure your tasks and logic between them.

## Webhook

Below you can find an example webhook payload for image sentiment task

```
{
    "id": 65374401,
    "action": "fs.workflow",
    "timestamp": 1551126197,
    "text": {
        "workflow": "c516549f-3755-4fb5-85a4-15ae4b31d475",
        "createdAt": "2020-01-25T20:21:53.929686791Z",
        "updatedAt": "2020-01-25T20:21:56.716186597Z",
        "sources": [\
            "H2swKXwhRxKFrylakLwcd"\
        ],
        "results": {
            "image_sentiment_1551120182170": {
                "data": {
                    "emotions": {
                        "HAPPY": 99.25,
                        "SURPRISED": 0.40,
                        "CALM": 0.18,
                        "CONFUSED": 0.05,
                        "ANGRY": 0.04,
                        "SAD": 0.03,
                        "FEAR": 0.01,
                        "DISGUSTED": 0.01
                    }
                }
            }
        },
        "status": "Finished"
    }
}
```

Please visit the [webhooks](https://www.filestack.com/docs/api/webhooks/#workflow) documentation page to learn more.
