// Step 1: Generate the logo prompt
const promptHeaders = new Headers();
promptHeaders.append("Content-Type", "application/json");
promptHeaders.append("api-key", "<YOUR_API_KEY>"); // Replace with your API key
const promptRaw = JSON.stringify({
"command_name": "logo_prompt",
"description": "droplinked , we are a company offering web3 based and onchain solution to businesses and indivisuals .",
"category": "technology"
});
const promptRequestOptions = {
method: "POST",
headers: promptHeaders,
body: promptRaw,
redirect: "follow"
};
fetch("https://text-tad.droplinked.workers.dev/", promptRequestOptions)
.then((response) => response.text())
.then((promptResult) => {
// Step 2: Submit the prompt to Segmind
const segmindHeaders = new Headers();
segmindHeaders.append("x-api-key", "<YOUR_SEGMIND_API_KEY>"); // Replace with your Segmind API key
segmindHeaders.append("Content-Type", "application/json");
const segmindRaw = JSON.stringify({
"input_logo": promptResult,
"input_seed": "1"
});
const segmindRequestOptions = {
method: "POST",
headers: segmindHeaders,
body: segmindRaw,
redirect: "follow"
};
return fetch("https://api.segmind.com/workflows/67792adb99c1698a193130bb-v5", segmindRequestOptions)
.then((response) => response.json())
.then((segmindResult) => {
const pollUrl = segmindResult.poll_url;
// Step 3: Poll for the final image URL
const pollHeaders = new Headers();
pollHeaders.append("x-api-key", "<YOUR_SEGMIND_API_KEY>");
const pollRequestOptions = {
method: "GET",
headers: pollHeaders,
redirect: "follow"
};
// Polling loop (simplified for example; implement proper interval logic)
const pollForResult = () => {
fetch(pollUrl, pollRequestOptions)
.then((pollResponse) => pollResponse.json())
.then((pollResult) => {
if (pollResult.status === "COMPLETED") {
const output = JSON.parse(pollResult.output);
const imageUrl = output[0].value.data;
console.log("Final Image URL:", imageUrl);
// Display the image
const imgElement = document.createElement("img");
imgElement.src = imageUrl;
document.body.appendChild(imgElement);
} else {
console.log("Still processing, status:", pollResult.status);
setTimeout(pollForResult, 5000); // Retry after 5 seconds
}
})
.catch((error) => console.error("Polling Error:", error));
};
pollForResult();
});
})
.catch((error) => console.error("Prompt Generation Error:", error));