ZUB Mega Tool - AI Lyrics Rewriter
async function generateNewLyrics() {
const apiKey = document.getElementById("apiKey").value.trim();
const originalLyrics = document.getElementById("lyricsInput").value.trim();
const style = document.getElementById("styleOption").value;
const mode = document.getElementById("rewriteMode").value;
const outputBox = document.getElementById("outputResult");
const loader = document.getElementById("loading");
if (!apiKey) {
alert("Kripya pehle valid API Key dalein.");
return;
}
if (!originalLyrics) {
alert("Kripya pehle original lyrics dalein.");
return;
}
loader.style.display = "block";
outputBox.value = "Processing...";
const promptText = `Task: Rewrite lyrics. Style: ${style}. Mode: ${mode}. Write a completely original, fresh set of rhyming lyrics inspired by the mood of the following input: \n\n${originalLyrics}`;
try {
const url = `https://generativelanguage.googleapis.com/v1beta/models/gemini-2.5-flash:generateContent?key=${apiKey}`;
const response = await fetch(url, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
contents: [{ parts: [{ text: promptText }] }]
})
});
const data = await response.json();
if (data.error) {
outputBox.value = "API Error Code " + data.error.code + ": " + data.error.message;
return;
}
if (data.candidates && data.candidates[0].content && data.candidates[0].content.parts[0].text) {
outputBox.value = data.candidates[0].content.parts[0].text;
} else {
outputBox.value = "Error: Model ne response deliver nahi kiya. Full response: " + JSON.stringify(data);
}
} catch (err) {
outputBox.value = "Network Error: " + err.message;
} finally {
loader.style.display = "none";
}
}