// Copyright (c) 2024 Baidu, Inc. All Rights Reserved. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. import * as http from 'http'; import {Text2Image, setEnvVariable} from '../index'; // 修改env文件 // setEnvVariable('QIANFAN_AK','***'); // setEnvVariable('QIANFAN_SK','***'); // 直接读取env const client = new Text2Image(); // 手动传AK/SK 测试 // const client = new Eembedding({ QIANFAN_AK: '***', QIANFAN_SK: '***'}); // 手动传ACCESS_KEY/ SECRET_KEY测试 // const client = new Eembedding({ QIANFAN_ACCESS_KEY: '***', QIANFAN_SECRET_KEY: '***' }); // AK/SK 测试 async function main() { const resp = await client.text2Image({ prompt: '生成爱莎公主的图片', size: '768x768', n: 1, steps: 20, sampler_index: 'Euler a', }, 'Stable-Diffusion-XL'); console.log(resp); const base64Image = resp.data[0].b64_image; // 创建一个简单的服务器 const server = http.createServer((req, res) => { res.writeHead(200, {'Content-Type': 'text/html'}); let html = `
`; res.end(html); }); const port = 3001; server.listen(port, () => { console.log(`服务器运行在 http://localhost:${port}`); }); } main();