php百度智能云调用Stable-Diffusion-XL文本生成图片api示例代码

代码语言:php

所属分类:其他

代码描述:php百度智能云调用Stable-Diffusion-XL文本生成图片api示例代码,先创建应用, 获取密钥,地址:https://console.bce.baidu.com/qianfan/ais/console/applicationConsole/application

代码标签: php 百度 智能云 调用 Stable Diffusion XL 文本 生成 图片 api 示例

下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开

<?php

// API Key和Secret Key
$app_id = '';
$api_key = '';
$secret_key = '';




$url = 'https://aip.baidubce.com/oauth/2.0/token';
$params = array(
    'grant_type' => 'client_credentials',
    'client_id' => $api_key,
    'client_secret' => $secret_key
);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($ch);

curl_close($ch);

$result = json_decode($response, true);

$access_token = $result['access_token'];




// Set up the data to be sent via POST
$data = [
    "prompt" => "a cat on the sea",
    "negative_prompt" => "white",
    "size" => "1024x1024",
    "steps" => 20,
    "n" => 1,
    "sampler_index" => "DPM++ SDE Karras"
];

// Initialize a cURL s.........完整代码请登录后点击上方下载按钮下载查看

网友评论0