码云 Gitee IDE 全新上线——支持 Git 管理的轻量在线编码环境
Watch Star

khs1994-php / tencent-aiPHP

加入码云
与超过 300 万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
Tencent AI SDK
Loading...
README.md 3.13 KB

Tencent AI SDK

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

本项目为本人 PHP 练手项目,仅供参考!

Require

  • PHP 7.1+

Installation

To Use Tencent AI SDK, simply:

$ composer require khs1994/tencent-ai

For latest commit version:

$ composer config minimum-stability dev

$ composer require khs1994/tencent-ai dev-master

Usage

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

use TencentAI\TencentAI;
use TencentAI\Error\TencentAIError;

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

try {
    $output = $ai->face()->detect($image);
} catch (TencentAIError $e) {
    $output = $e->getErrorAsArray();
}

// default return array

var_dump($output);

Laravel

$ php artisan vendor:publish --tag=config

Then edit config in config/tencent-ai.php

use TencentAI;

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

try {
    // call by facade
    $output = TencentAI::face()->detect($image);
    
    // call by helper function
    // tencent_ai()->face()->detect($image);
} catch (TencentAIError $e) {
    $output = $e->getErrorAsArray();
}

// default return array

var_dump($output);

// 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);
    }
}

PHP CaaS

Powered By khs1994-docker/lnmp

CI/CD

搜索帮助