안녕하세요 karlo API를 사용해서 이미지를 만들고있는 웹페이지를 만들고있는데 karlo API를 사용하는중에 이미지 생성에서 width나 height같은 요소들을 사용할려고할때 에러가 생깁니다 개발환경은 VSCODE를 사용하고 node.js를 사용하고 있습니다.
async function t2i(prompt, negativePrompt, imageformat, returntype, imageQuality, samples) {
try {
const response = await axios.post(
'https://api.kakaobrain.com/v2/inference/karlo/t2i',
{
prompt,
negative_prompt: negativePrompt,
image_format: imageformat,
return_type : returntype,
image_quality: imageQuality,
samples
},
{
headers: {
'Authorization': `KakaoAK ${REST_API_KEY}`,
'Content-Type': 'application/json'
}
}
);
// Convert the response to JSON format
const responseData = response.data;
// Extract the image URL from the response
const imageUrl = responseData.images[0].image;
console.log('Image URL:', imageUrl);
console.log(responseData.images[0]);
// Send the image URL to the client
return imageUrl;
} catch (error) {
console.error('Error:', error.message);
return null;
}
}
// Handle form submission
app.post('/generateImage', async (req, res) => {
const prompt = req.body.prompt;
const negativePrompt =
"paper, cake, low quality, low contrast, draft, amateur, cut off, cropped, frame, object out of frame, out of frame, body out of frame, text, letter, signature, watermark";
const imageformat = "png";
const returntype = "url";
const imageQuality = 80;
const samples = 2;
console.log("Input:", req.body.width);
const width = 384;
console.log("Parsed Width:", width);
console.log(imageQuality);
const imageUrl = await t2i(prompt, negativePrompt, imageformat, returntype, imageQuality, samples);
if (imageUrl) {
res.json({ imageUrl }); // Sending JSON response
} else {
// If image generation fails, send an error response
res.status(500).send('Error generating image');
}
});
<h1>Image Generator</h1>
<div class="container">
<form action="/generateImage" method="post">
<label for="prompt">Prompt:</label>
<!-- <input type="text" id="prompt" name="prompt" placeholder="Enter your prompt" required> -->
<textarea name="prompt" id="prompt" cols="30" rows="10" placeholder="Enter your prompt" required></textarea><br>
<label for="width">Width</label>
<input type="text" name="width" id="width">
<button type="submit">Generate Image</button>
</form>
</div>
이러한 코드를 구성하였지만 wiidth같은 요소들을 유저가 작성한것을 가져와서 사용하고싶습니다 어떤식으로 코드를 고치면 될까요?