<commit_before># clarifai-php

![Travis Build Status](https://travis-ci.org/darrynten/clarifai-php.svg?branch=master)
![StyleCI Status](https://styleci.io/repos/81687310/shield?branch=master)
[![codecov](https://codecov.io/gh/darrynten/clarifai-php/branch/master/graph/badge.svg)](https://codecov.io/gh/darrynten/clarifai-php)
![Packagist Version](https://img.shields.io/packagist/v/darrynten/clarifai-php.svg)
![MIT License](https://img.shields.io/github/license/darrynten/clarifai-php.svg)

[Clarifai API](https://developer.clarifai.com/docs/) client for PHP

This is a 100% fully unit tested and (mostly) fully featured unofficial PHP
client for Clarifai

> Clarifai is an artificial intelligence company that excels in visual
recognition, solving real-world problems for businesses and developers
alike.

```bash
composer require darrynten/clarifai-php
```

PHP 7.0+

## Basic use

The API is rather simple, and consists of Inputs, Concepts and Models.

### Definitions

#### Inputs

You send inputs (images) to the service and it returns predictions. In
addition to receiving predictions on inputs, you can also 'save' inputs
and their predictions to later search against. You can also 'save' inputs
with concepts to later train your own model.

#### Model

Clarifai provides many different models that 'see' the world differently.
A model contains a group of concepts. A model will only see the concepts
it contains.

There are times when you wish you had a model that sees the world the way
you see it. The API allows you to do this. You can create your own model
and train it with your own images and concepts. Once you train it to see
how you would like it to see, you can then use that model to make
predictions.

You do not need many images to get started. We recommend starting with 10
and adding more as needed.

#### Concepts

Concepts play an important role in creating your own models using your
own concepts. Concepts also help you search for inputs.

When you add a concept to an input, you need to indicate whether the
concept is present in the image or if it is not present.

## Features

This is the basic outline of the project and is a work in progress.

Checkboxes have been placed at each section, please check them off
in this readme when submitting a pull request for the features you
have covered.

### Application base

* Guzzle is used for the communications
* The library has 100% test coverage
* The library supports framework-agnostic caching so you don't have to
worry about which framework your package that uses this package is going
to end up in.

The client is not 100% complete and is a work in progress, details below.

The structure is heavily inspired by [The official JS client](https://github.com/Clarifai/clarifai-javascript)

### Authentication

Access is handled via oauth2.

You would need to initialise the client with your Client ID and Secret.

```php
$this->clarifai = new Clarifai('clientId', 'clientSecret');
```

### Predict

This is a basic library usage example that uses a predict call. The model name is `aaa03c23b3724a16a56b629203edc62c`

```php

include 'vendor/autoload.php';

$clarifai = new \DarrynTen\Clarifai\Clarifai(
    CLIENT_ID,
    CLIENT_SECRET
);

$modelResult = $clarifai->getModel()->predictUrl(
    'https://samples.clarifai.com/metro-north.jpg',
    \DarrynTen\Clarifai\Repository\Model::GENERAL
);

echo json_encode($modelResult);

```

The response (abridged) would be:

```js
{
  "status":{
     "code":10000,
     "description":"Ok"
  },
  "outputs":[
     {
        "id":"db1b183a95a042d3bd873f8ca69ae2e6",
        "status":{
           "code":10000,
           "description":"Ok"
        },
        "created_at":"2017-02-14T03:18:54.548733Z",
        "model":{
           "name":"general-v1.3",
           "id":"aaa03c23b3724a16a56b629203edc62c",
           "created_at":"2016-03-09T17:11:39.608845Z",
           "app_id":null,
           "output_info":{
              "message":"Show output_info with: GET \/models\/{model_id}\/output_info",
              "type":"concept"
           },
           "model_version":{
              "id":"aa9ca48295b37401f8af92ad1af0d91d",
              "created_at":"2016-07-13T01:19:12.147644Z",
              "status":{
                 "code":21100,
                 "description":"Model trained successfully"
              }
           }
        },
        "input":{
           "id":"db1b183a95a042d3bd873f8ca69ae2e6",
           "data":{
              "image":{
                 "url":"https:\/\/samples.clarifai.com\/metro-north.jpg"
              }
           }
        },
        "data":{
           "concepts":[
              {
                 "id":"ai_HLmqFqBf",
                 "name":"\u043f\u043e\u0435\u0437\u0434",
                 "app_id":null,
                 "value":0.9989112
              },
              // and several others
              {
                 "id":"ai_VSVscs9k",
                 "name":"\u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b",
                 "app_id":null,
                 "value":0.9230834
              }
           ]
        }
     }
  ]
}
```

This can happen either with an image URL:

```php
    $modelResult = $clarifai->getModel()->predictPath(
        '/user/images/image.png',
        \DarrynTen\Clarifai\Repository\Model::GENERAL
    );
```

or b64 encoded data:

```php
    $modelResult = $clarifai->getModel()->predictEncoded(
        ENCODED_IMAGE_HASH,
        \DarrynTen\Clarifai\Repository\Model::GENERAL
    );
```

## Documentation

This will eventually fully mimic the documentation available on the site.
https://developer.clarifai.com/guide

Each section must have a short explaination and some example code like on
the API docs page.

Checked off bits are complete.

- [x] Inputs<commit_msg>Old predict method documentation fix<commit_after># clarifai-php

![Travis Build Status](https://travis-ci.org/darrynten/clarifai-php.svg?branch=master)
![StyleCI Status](https://styleci.io/repos/81687310/shield?branch=master)
[![codecov](https://codecov.io/gh/darrynten/clarifai-php/branch/master/graph/badge.svg)](https://codecov.io/gh/darrynten/clarifai-php)
![Packagist Version](https://img.shields.io/packagist/v/darrynten/clarifai-php.svg)
![MIT License](https://img.shields.io/github/license/darrynten/clarifai-php.svg)

[Clarifai API](https://developer.clarifai.com/docs/) client for PHP

This is a 100% fully unit tested and (mostly) fully featured unofficial PHP
client for Clarifai

> Clarifai is an artificial intelligence company that excels in visual
recognition, solving real-world problems for businesses and developers
alike.

```bash
composer require darrynten/clarifai-php
```

PHP 7.0+

## Basic use

The API is rather simple, and consists of Inputs, Concepts and Models.

### Definitions

#### Inputs

You send inputs (images) to the service and it returns predictions. In
addition to receiving predictions on inputs, you can also 'save' inputs
and their predictions to later search against. You can also 'save' inputs
with concepts to later train your own model.

#### Model

Clarifai provides many different models that 'see' the world differently.
A model contains a group of concepts. A model will only see the concepts
it contains.

There are times when you wish you had a model that sees the world the way
you see it. The API allows you to do this. You can create your own model
and train it with your own images and concepts. Once you train it to see
how you would like it to see, you can then use that model to make
predictions.

You do not need many images to get started. We recommend starting with 10
and adding more as needed.

#### Concepts

Concepts play an important role in creating your own models using your
own concepts. Concepts also help you search for inputs.

When you add a concept to an input, you need to indicate whether the
concept is present in the image or if it is not present.

## Features

This is the basic outline of the project and is a work in progress.

Checkboxes have been placed at each section, please check them off
in this readme when submitting a pull request for the features you
have covered.

### Application base

* Guzzle is used for the communications
* The library has 100% test coverage
* The library supports framework-agnostic caching so you don't have to
worry about which framework your package that uses this package is going
to end up in.

The client is not 100% complete and is a work in progress, details below.

The structure is heavily inspired by [The official JS client](https://github.com/Clarifai/clarifai-javascript)

### Authentication

Access is handled via oauth2.

You would need to initialise the client with your Client ID and Secret.

```php
$this->clarifai = new Clarifai('clientId', 'clientSecret');
```

### Predict

This is a basic library usage example that uses a predict call. The model name is `<KEY>`

```php

include 'vendor/autoload.php';

$clarifai = new \DarrynTen\Clarifai\Clarifai(
    CLIENT_ID,
    CLIENT_SECRET
);

$modelResult = $clarifai->getModelRepository()->predictUrl(
    'https://samples.clarifai.com/metro-north.jpg',
    \DarrynTen\Clarifai\Repository\ModelRepository::GENERAL
);

echo json_encode($modelResult);

```

The response (abridged) would be:

```js
{
  "status":{
     "code":10000,
     "description":"Ok"
  },
  "outputs":[
     {
        "id":"db1b183a95a042d3bd873f8ca69ae2e6",
        "status":{
           "code":10000,
           "description":"Ok"
        },
        "created_at":"2017-02-14T03:18:54.548733Z",
        "model":{
           "name":"general-v1.3",
           "id":"<KEY>",
           "created_at":"2016-03-09T17:11:39.608845Z",
           "app_id":null,
           "output_info":{
              "message":"Show output_info with: GET \/models\/{model_id}\/output_info",
              "type":"concept"
           },
           "model_version":{
              "id":"aa9ca48295b37401f8af92ad1af0d91d",
              "created_at":"2016-07-13T01:19:12.147644Z",
              "status":{
                 "code":21100,
                 "description":"Model trained successfully"
              }
           }
        },
        "input":{
           "id":"db1b183a95a042d3bd873f8ca69ae2e6",
           "data":{
              "image":{
                 "url":"https:\/\/samples.clarifai.com\/metro-north.jpg"
              }
           }
        },
        "data":{
           "concepts":[
              {
                 "id":"ai_HLmqFqBf",
                 "name":"\u043f\u043e\u0435\u0437\u0434",
                 "app_id":null,
                 "value":0.9989112
              },
              // and several others
              {
                 "id":"ai_VSVscs9k",
                 "name":"\u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b",
                 "app_id":null,
                 "value":0.9230834
              }
           ]
        }
     }
  ]
}
```

This can happen either with an image URL:

```php
    $modelResult = $clarifai->getModelRepository()->predictPath(
        '/user/images/image.png',
        \DarrynTen\Clarifai\Repository\ModelRepository::GENERAL
    );
```

or b64 encoded data:

```php
    $modelResult = $clarifai->getModelRepository()->predictEncoded(
        ENCODED_IMAGE_HASH,
        \DarrynTen\Clarifai\Repository\ModelRepository::GENERAL
    );
```

## Documentation

This will eventually fully mimic the documentation available on the site.
https://developer.clarifai.com/guide

Each section must have a short explaination and some example code like on
the API docs page.

Checked off bits are complete.

- [x] Inputs
{'fraction_non_alphanumeric': 0.1078845325290823, 'fraction_numerical': 0.04118914261094356, 'mean_word_length': 2.7792250081406706, 'pattern_counts': {'":': 76, '<': 5, '<?xml version=': 0, '>': 21, 'https://': 20, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4273433', 'n_tokens_mistral': 3910, 'n_tokens_neox': 3532, 'n_words': 1095}