PHP code example of bigstylee / clarifai-php

1. Go to this page and download the library: Download bigstylee/clarifai-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bigstylee / clarifai-php example snippets


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



$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);


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

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

    $input = new Input();
    $input->setImage('https://samples.clarifai.com/metro-north.jpg')->isUrl();
    $inputResult = $clarifai->getInputRepository()->add($input);

    $input = new Input();
    $input->setImage('/samples.clarifai.com/metro-north.jpg')->isPath();
    $inputResult = $clarifai->getInputRepository()->add($input);

    $input = new Input();
    $input->setImage(ENCODED_IMAGE_HASH)->isEncoded();
    $inputResult = $clarifai->getInputRepository()->add($input);

    $input1 = new Input();
    $input1->setImage('https://samples.clarifai.com/metro-north.jpg')->isUrl()->setId('id1');
    $input2 = new Input();
    $input2->setImage('https://samples.clarifai.com/puppy.jpeg')->isUrl()->setId('id2');
    $inputResult = $clarifai->getInputRepository()->add([$input1, $input2]);

    $concept = new Concept();
    $concept->setId('boscoe')->setValue(true);

    $input = new Input();
    $input->setImage('https://samples.clarifai.com/puppy.jpeg')->isUrl()
        ->setConcepts([$concept]);

    $inputResult = $clarifai->getInputRepository()->add($input);

    $input = new Input();
    $input->setImage('https://samples.clarifai.com/metro-north.jpg')->isUrl()
        ->setMetaData([['key' => 'value', 'list' => [1, 2, 3]]);
    $inputResult = $clarifai->getInputRepository()->add($input);

    $input = new Input();
    $input->setImage('https://samples.clarifai.com/metro-north.jpg')->isUrl()
        ->setCrop([0.2, 0.4, 0.3, 0.6]);
    $inputResult = $clarifai->getInputRepository()->add($input);

    $inputResult = $clarifai->getInputRepository()->get();

    $inputResult = $clarifai->getInputRepository()->getById('id');

    $inputResult = $clarifai->getInputRepository()->getStatus();

    $concept1 = new Concept();
    $concept1->setId('tree')->setValue(true);
    
    $concept2 = new Concept();
    $concept2->setId('water')->setValue(false);

    $modelResult = $clarifai->getInputRepository()->mergeInputConcepts([$inputId => [$concept1, $concept2]]);

    $concept1 = new Concept();
    $concept1->setId('mattid2')->setValue(true);
    
    $concept2 = new Concept();
    $concept2->setId('ferrari')->setValue(false);

    $modelResult = $clarifai->getInputRepository()->deleteInputConcepts([$inputId => [$concept1, $concept2]]);

    $concept1 = new Concept();
    $concept1->setId('tree')->setValue(true);
    
    $concept2 = new Concept();
    $concept2->setId('water')->setValue(false);
    
    $concept3 = new Concept();
    $concept3->setId('mattid2')->setValue(true);
    
    $concept4 = new Concept();
    $concept4->setId('ferrari')->setValue(false);

    $modelResult = $clarifai->getInputRepository()->mergeInputConcepts(
        [
            $inputId1 => [$concept1, $concept2],
            $inputId2 => [$concept3, $concept4],
        ]
    );

    $concept1 = new Concept();
    $concept1->setId('tree')->setValue(true);
    
    $concept2 = new Concept();
    $concept2->setId('water')->setValue(false);
    
    $concept3 = new Concept();
    $concept3->setId('mattid2')->setValue(true);
    
    $concept4 = new Concept();
    $concept4->setId('ferrari')->setValue(false);

    $modelResult = $clarifai->getInputRepository()->deleteInputConcepts(
        [
            $inputId1 => [$concept1, $concept2],
            $inputId2 => [$concept3, $concept4],
        ]
    );

    $inputResult = $clarifai->getInputRepository()->deleteById('id');

    $inputResult = $clarifai->getInputRepository()->deleteByIdArray(['id1', 'id2']);

    $inputResult = $clarifai->getInputRepository()->deleteAll();

    $model = new Model();
    $model->setId('petsID');
    $modelResult = $clarifai->getModelRepository()->create($model);

    $concept = new Concept();
    $concept->setId('boscoe');

    $model= new Model();
    $model->setId('petsId')
        ->setConcepts([$concept])
        ->setConceptsMutuallyExclusive(false)
        ->setClosedEnvironment(false);

    $modelResult = $clarifai->getModelRepository()->create($model);

    $concept = new Concept();
    $concept->setId('dogs');

    $modelResult = $clarifai->getModelRepository()->mergeModelConcepts([$modelId => [$concept]]);

    $concept = new Concept();
    $concept->setId('dogs');

    $modelResult = $clarifai->getModelRepository()->deleteModelConcepts([$modelId => [$concept]]);

    $model->setName('newname')
        ->setClosedEnvironment(true)
        ->setConceptsMutuallyExclusive(true);

    $modelResult = $clarifai->getModelRepository()->update($model);

    $modelResult = $clarifai->getModelRepository()->get();

    $modelResult = $clarifai->getModelRepository()->getById($modelId);

    $modelResult = $clarifai->getModelRepository()->getOutputInfoById($modelId);

    $modelResult = $clarifai->getModelRepository()->getModelVersions($modelId);

    $modelResult = $clarifai->getModelRepository()->getModelVersionById($modelId, $versionId);

    $modelResult = $clarifai->getModelRepository()->getTrainingInputsById($modelId);

    $modelResult = $clarifai->getModelRepository()->getTrainingInputsByVersion($modelId, $versionId);

    $modelResult = $clarifai->getModelRepository()->deleteById($modelId);

    $modelResult = $clarifai->getModelRepository()->deleteVersionById($modelId, $versionId);

    $modelResult = $clarifai->getModelRepository()->deleteAll();

    $modelResult = $clarifai->getModelRepository()->train($id);

    $modelResult = $clarifai->getSearchModelRepository()->searchByNameAndType($modelName, 'concept');

    $concept1 = new Concept();
    $concept1->setName('dog')->setValue(true);
    
    $concept2 = new Concept();
    $concept2->setName('cat');
        
    $inputResult = $clarifai->getSearchInputRepository()->searchByPredictedConcepts([$concept1, $concept2]);

    $concept1 = new Concept();
    $concept1->setName('dog');
    
    $concept2 = new Concept();
    $concept2->setName('cat');
        
    $inputResult = $clarifai->getSearchInputRepository()->searchByUserSuppliedConcepts([$concept1, $concept2]);

    $metadata = ['key'=> 'value'];

    $inputResult = $clarifai->getSearchInputRepository()->searchByCustomMetadata([$metadata]);

    $input = new Input();
    $input->setImage('https://samples.clarifai.com/metro-north.jpg');
        
    $inputResult = $clarifai->getSearchInputRepository()->searchByReversedImage([$input]);

    $input = new Input();
    $input->setImage('https://samples.clarifai.com/metro-north.jpg');
        
    $inputResult = $clarifai->getSearchInputRepository()->searchByMatchUrl([$input]);

    $concept1 = new Concept();
    $concept1->setName('dog');
    
    $concept2 = new Concept();
    $concept2->setName('cat');
        
    $inputResult = $clarifai->getSearchInputRepository()->search(
        [
            \DarrynTen\Clarifai\Repository\SearchInputRepository::INPUT_CONCEPTS => [$concept1],
            \DarrynTen\Clarifai\Repository\SearchInputRepository::OUTPUT_CONCEPTS => [$concept2]
        ]
    );

    $concept1 = new Concept();
    $concept1->setName('dog');
    
    $concept2 = new Concept();
    $concept2->setName('cat');
    
    $input = new Input();
    $input->setImage('https://samples.clarifai.com/metro-north.jpg');
    
    $metadata = ['key' => 'value'];
        
    $inputResult = $clarifai->getSearchInputRepository()->search(
        [
            SearchInputRepository::INPUT_CONCEPTS => [$concept1],
            SearchInputRepository::OUTPUT_CONCEPTS => [$concept2],
            SearchInputRepository::IMAGE => [$input],
            SearchInputRepository::METADATA => [$metadata],
        ]
    );

    $inputResult = $clarifai->getInputRepository()->setPage(2)->setPerPage(20)->get();
bash
composer