const generateBtn = document.getElementById('generateBtn');
const userInput = document.getElementById('userInput');
const tagsContainer = document.getElementById('tagsContainer');
// Replace with your Gemini API key
const GEMINI_API_KEY = 'YOUR_GEMINI_API_KEY';
generateBtn.addEventListener('click', async () => {
const inputText = userInput.value.trim();
if (!inputText) {
alert('Please enter a topic, keywords, or title.');
return;
}
try {
const tags = await generateTags(inputText);
displayTags(tags);
} catch (error) {
console.error('Error generating tags:', error);
alert('Failed to generate tags. Please try again.');
}
});
async function generateTags(inputText) {
const prompt = `Generate 10 to 15 YouTube tags related to: ${inputText}. Return the tags as a comma-separated list.`;
const response = await fetch(`https://api.gemini.com/v1/generate?key=${GEMINI_API_KEY}`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ prompt }),
});
const data = await response.json();
return data.tags.split(',').map(tag => tag.trim());
}
function displayTags(tags) {
tagsContainer.innerHTML = ''; // Clear previous tags
tags.forEach(tag => {
const tagElement = document.createElement('div');
tagElement.classList.add('tag');
tagElement.textContent = tag;
tagsContainer.appendChild(tagElement);
});
}