khs1994-php / tencent-ai

:penguin: Tencent AI 腾讯 AI PHP SDK

Home Page:https://packagist.org/packages/khs1994/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Tencent AI SDK

GitHub stars PHP from Packagist GitHub (pre-)release Build Status StyleCI codecov

微信订阅号

关注项目作者微信订阅号,接收项目最新动态

Installation

To Use Tencent AI SDK, simply:

$ composer require khs1994/tencent-ai

For latest commit version:

$ composer require khs1994/tencent-ai dev-master

Usage

<?php

require __DIR__.'/vendor/autoload.php';

use TencentAI\TencentAI;
use TencentAI\Exception\TencentAIException;

const APP_ID = 1106560031;
const APP_KEY = 'ZbRY9cf72TbDO0xb';

# you can set return format and request timeout

$ai = TencentAI::getInstance(APP_ID, APP_KEY, false, 10);

$image = __DIR__.'/path/name.jpg';

// must try-catch exception

try {
    $result = $ai->face()->detect($image);
} catch (TencentAIException $e) {
    $result = $e->getExceptionAsArray();
}

// default return array

var_dump($result);

Laravel

$ php artisan vendor:publish --tag=config

Then edit config in config/tencent-ai.php

<?php

use TencentAI;
use TencentAI\Exception\TencentAIException;

$image = __DIR__.'/path/name.jpg';

try {
    // call by facade
    $result = TencentAI::face()->detect($image);

    // call by helper function
    // tencent_ai()->face()->detect($image);
} catch (TencentAIException $e) {
    $result = $e->getExceptionAsArray();
}

// default return array

var_dump($result);

// use DI

class AI
{
    public $tencent_ai;

    public function __construct(\TencentAI\TencentAI $tencent_ai)
    {
        $this->tencent_ai = $tencent_ai;
    }

    public function demo()
    {
        $image = __DIR__.'/path/name.jpg';

        return $this->tencent_ai->face()->detect($image);
    }
}

Tests

export TENCENT_AI_APP_ID
export TENCENT_AI_APP_KEY

Who use it?

PHP CaaS

Powered By khs1994-docker/lnmp

About

:penguin: Tencent AI 腾讯 AI PHP SDK

https://packagist.org/packages/khs1994/

License:MIT License


Languages

Language:PHP 99.6%Language:Dockerfile 0.3%Language:Shell 0.1%