成人无码视频,亚洲精品久久久久av无码,午夜精品久久久久久毛片,亚洲 中文字幕 日韩 无码

資訊專欄INFORMATION COLUMN

利用百度ai實(shí)現(xiàn)文本和圖片審核

shaonbean / 3812人閱讀

摘要:接下來就簡單說下怎么做吧首先打開百度開發(fā)平臺(tái)注冊(cè)一個(gè)賬號(hào)注冊(cè)賬號(hào),進(jìn)入控制臺(tái)創(chuàng)建自己的應(yīng)用,獲取和秘鑰進(jìn)入文檔頁文本審核圖像審核文檔很詳細(xì),實(shí)現(xiàn)用戶發(fā)布內(nèi)容審核圖片審核還是很方便簡單的。

之前做平臺(tái)內(nèi)容發(fā)布審核都是自己構(gòu)建一套違禁詞庫,在代碼中利用詞庫判斷用戶發(fā)布的內(nèi)容,現(xiàn)在可以使用百度ai api完成這個(gè)功能。接下來就簡單說下怎么做吧:

首先打開百度ai 開發(fā)平臺(tái) 注冊(cè)一個(gè)賬號(hào):

注冊(cè)賬號(hào),進(jìn)入控制臺(tái)

創(chuàng)建自己的應(yīng)用,獲取apikey 和秘鑰

進(jìn)入文檔頁 文本審核:

圖像審核:

文檔很詳細(xì),實(shí)現(xiàn)用戶發(fā)布內(nèi)容審核 圖片審核還是很方便簡單的。我沒有使用官方的sdk,簡單的整合了一下作為練手,以下是我簡單的代碼demo:
圖片描述

class Sentive
{
    protected $accessTokenUrl = "https://aip.baidubce.com/oauth/2.0/token";//獲取token url
    protected $textUrl = "https://aip.baidubce.com/rest/2.0/antispam/v2/spam";//文本審核url
    protected $imgUrl = "https://aip.baidubce.com/api/v1/solution/direct/img_censor";//圖片審核url
    protected $avatarUrl = "https://aip.baidubce.com/rest/2.0/solution/v1/face_audit";//頭像審核url

    protected $grant_type;

    protected $client_id;

    protected $client_secret;

    function __construct()
    {
        $this->grant_type = "client_credentials";
        $this->client_id = "xxx";//API Key
        $this->client_secret = "xxx";//Secret Key
    }

    static function request($url = "", $param = "")
    {
        if (empty($url) || empty($param)) {
            return false;
        }

        $postUrl = $url;
        $curlPost = $param;
        $curl = curl_init();//初始化curl
        curl_setopt($curl, CURLOPT_URL, $postUrl);//抓取指定網(wǎng)頁
        curl_setopt($curl, CURLOPT_HEADER, 0);//設(shè)置header
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//要求結(jié)果為字符串且輸出到屏幕上
        curl_setopt($curl, CURLOPT_POST, 1);//post提交方式
        curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost);
        $data = curl_exec($curl);//運(yùn)行curl
        curl_close($curl);


        return $data;
    }

    static function request_post($url = "", $param = array(), $type)
    {
        if (empty($url) || empty($param)) {
            return false;
        }

        $postUrl = $url;
        $curlPost = $param;
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $postUrl);
        curl_setopt($curl, CURLOPT_HEADER, 0);
        // 要求結(jié)果為字符串
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        // post方式
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost);
        if ($type == "text") {
            curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded"));
        } else {
            curl_setopt($curl, CURLOPT_HTTPHEADER, array("Content-Type: application/json;charset=utf-8"));
        }
        curl_setopt($curl, CURLINFO_HEADER_OUT, true);
        $data = curl_exec($curl);
        $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);

        if ($code === 0) {
            throw new Exception(curl_error($curl));
        }
        curl_close($curl);
        return $data;
    }

    //獲取token
    public function getToken()
    {
        new Redis();
        $post_data["grant_type"] = $this->grant_type;
        $post_data["client_id"] = $this->client_id;
        $post_data["client_secret"] = $this->client_secret;
        $o = "";
        foreach ($post_data as $k => $v) {
            $o .= "$k=" . urlencode($v) . "&";
        }
        $post_data = substr($o, 0, -1);
        $res = self::request($this->accessTokenUrl, $post_data);
        $redis->setkey("filterToken", json_decode($res, true)["access_token"]);
        return json_decode($res, true)["access_token"];
    }

    //文本審核
    public function textVerify($data)
    {
        new Redis();
        $token = $redis->get("filterToken");
        if (empty($token)) {
            $token = $this->getToken();
        }
        $curl = $this->textUrl . "?access_token=" . $token;
        $result = self::request_post($curl, $data, "text");
        return json_decode($result, true);
    }

    //圖片審核
    public function imgVerify($img)
    {
        $redis = new Redis();
        $token = $redis->get("filterToken");
        if (empty($token)) {
            $token = $this->getToken();
        }
        $curl = $this->imgUrl . "?access_token=" . $token;
        $bodys = array(
            "image" => $img,
            "scenes" => array("ocr",
                "face", "public", "politician", "antiporn", "terror", "webimage", "disgust",
                "watermark")
        );
        $bodys = json_encode($bodys);
        $result = self::request_post($curl, $bodys, "img");
        return json_decode($result, true);
    }


    //頭像審核
    public function avatarVerify($img)
    {
        $redis = new Redis();
        $token = $redis->get("filterToken");
        if (empty($token)) {
            $token = $this->getToken();
        }
        $curl = $this->avatarUrl . "?access_token=" . $token;
        $bodys = array(
            "configId" => "1",
            "images" => $img
        );
        $result = self::request_post($curl, $bodys, "text");
        return json_decode($result, true);
    }

}

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://m.hztianpu.com/yun/31402.html

相關(guān)文章

  • 知物由學(xué) | AI在Facebook清理有害內(nèi)容上扮演了什么角色?

    摘要:安全部隊(duì)迅速采取報(bào)復(fù)行動(dòng),焚燒村莊并進(jìn)行了持續(xù)數(shù)周的大規(guī)模屠殺。其中包括俄羅斯的選舉干預(yù)就業(yè)歧視,以及緬甸種族滅絕的幫兇。應(yīng)用機(jī)器學(xué)習(xí)小組的工程師對(duì)此表示贊同。 知物由學(xué)是網(wǎng)易云易盾打造的一個(gè)品牌欄目,詞語出自漢·王充《論衡·實(shí)知》。人,能力有高下之分,學(xué)習(xí)才知道事物的道理,而后才有智慧,不去求問就不會(huì)知道。知物由學(xué)希望通過一篇篇技術(shù)干貨、趨勢(shì)解讀、人物思考和沉淀給你帶來收獲的同時(shí),也...

    morgan 評(píng)論0 收藏0
  • AI說再見!“辣眼睛”的買家秀

    摘要:過審是指最終審核通過的高質(zhì)量買家秀,加精是指商家認(rèn)可的買家秀,普通則是上述兩種情況以外的其他買家秀。 showImg(https://segmentfault.com/img/remote/1460000018272118); 阿里妹導(dǎo)讀:提起買家秀和賣家秀,相信大家腦中會(huì)立刻浮現(xiàn)出諸多畫面。同一件衣服在不同人、光線、角度下,會(huì)呈現(xiàn)完全不同的狀態(tài)。運(yùn)營小二需從大量的買家秀中挑選出高質(zhì)量...

    yeooo 評(píng)論0 收藏0
  • 深圳云棲大會(huì)人工智能專場(chǎng):探索視頻+AI,玩轉(zhuǎn)智能視頻應(yīng)用

    摘要:在月日深圳云棲大會(huì)的人工智能專場(chǎng)中,阿里云視頻服務(wù)技術(shù)專家鄒娟將帶領(lǐng)大家探索熟悉的視頻場(chǎng)景中,技術(shù)如何應(yīng)用落地,解決實(shí)際業(yè)務(wù)場(chǎng)景中的問題。 摘要: 在人工智能時(shí)代,AI技術(shù)是如何在各行業(yè)和領(lǐng)域真正的發(fā)揮應(yīng)用和商業(yè)價(jià)值,帶來產(chǎn)業(yè)變革才是關(guān)鍵。在3月28日深圳云棲大會(huì)的人工智能專場(chǎng)中,阿里云視頻服務(wù)技術(shù)專家鄒娟將帶領(lǐng)大家探索熟悉的視頻場(chǎng)景中,AI技術(shù)如何應(yīng)用落地,解決實(shí)際業(yè)務(wù)場(chǎng)景中的問題。...

    李昌杰 評(píng)論0 收藏0
  • 如何通過人工智能“避開”內(nèi)容安全的“坑”?

    摘要:人工智能技術(shù)的初步應(yīng)用隨著網(wǎng)絡(luò)強(qiáng)國戰(zhàn)略思想加強(qiáng)網(wǎng)絡(luò)內(nèi)容建設(shè)等指導(dǎo)思想的推出和強(qiáng)化,內(nèi)容安全已經(jīng)成為互聯(lián)網(wǎng)企業(yè)生存和發(fā)展的生命線。 歡迎訪問網(wǎng)易云社區(qū),了解更多網(wǎng)易技術(shù)產(chǎn)品運(yùn)營經(jīng)驗(yàn)。 10月16日,2018年 AIIA人工智能開發(fā)者大會(huì)在蘇州舉辦。會(huì)議邀請(qǐng)了國內(nèi)外人工智能產(chǎn)業(yè)知名人物、國家政府主管部門、行業(yè)內(nèi)頂尖企業(yè)、知名學(xué)者代表、開源社區(qū)優(yōu)秀貢獻(xiàn)團(tuán)隊(duì)及個(gè)人,共同交流了技術(shù)現(xiàn)狀趨勢(shì)、生態(tài)...

    _DangJin 評(píng)論0 收藏0

發(fā)表評(píng)論

0條評(píng)論

閱讀需要支付1元查看
<