Spaces:
Build error
Build error
File size: 28,499 Bytes
0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec d9ccbf8 0a665ec |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>YouTube Shorts Generator</title>
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
darkMode: 'class',
theme: {
extend: {
colors: {
primary: '#5D5CDE',
}
}
}
};
</script>
<style>
.loading-spinner {
border: 4px solid rgba(0, 0, 0, 0.1);
border-left-color: #5D5CDE;
border-radius: 50%;
width: 50px;
height: 50px;
animation: spin 1s linear infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
.dark .loading-spinner {
border-color: rgba(255, 255, 255, 0.1);
border-left-color: #5D5CDE;
}
</style>
</head>
<body class="bg-white dark:bg-gray-900 text-gray-800 dark:text-gray-200 min-h-screen">
<div class="container mx-auto px-4 py-8 max-w-4xl">
<h1 class="text-3xl font-bold mb-4 text-center text-primary">YouTube Shorts Generator</h1>
<div class="mb-8 bg-gray-100 dark:bg-gray-800 p-6 rounded-lg shadow-md">
<div class="mb-4">
<label for="niche" class="block text-sm font-medium mb-1">Niche/Topic</label>
<input type="text" id="niche" placeholder="E.g., Fitness tips, Technology facts, Travel destinations" class="w-full px-4 py-2 rounded-md border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-700 text-base">
</div>
<div class="mb-4">
<label for="language" class="block text-sm font-medium mb-1">Language</label>
<select id="language" class="w-full px-4 py-2 rounded-md border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-700 text-base">
<option value="English">English</option>
<option value="Spanish">Spanish</option>
<option value="French">French</option>
<option value="German">German</option>
<option value="Italian">Italian</option>
<option value="Portuguese">Portuguese</option>
<option value="Russian">Russian</option>
<option value="Japanese">Japanese</option>
<option value="Chinese">Chinese</option>
<option value="Hindi">Hindi</option>
</select>
</div>
<div class="grid grid-cols-1 md:grid-cols-3 gap-4 mb-6">
<div>
<label for="text-generator" class="block text-sm font-medium mb-1">Text Generator</label>
<select id="text-generator" class="w-full px-4 py-2 rounded-md border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-700 text-base">
<option value="Claude-3.7-Sonnet">Claude-3.7-Sonnet</option>
<option value="GPT-4o">GPT-4o</option>
<option value="GPT-4o-mini">GPT-4o-mini</option>
<option value="Gemini-2.0-Flash">Gemini-2.0-Flash</option>
</select>
</div>
<div>
<label for="image-generator" class="block text-sm font-medium mb-1">Image Generator</label>
<select id="image-generator" class="w-full px-4 py-2 rounded-md border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-700 text-base">
<option value="FLUX-pro-1.1">FLUX-pro-1.1</option>
<option value="FLUX-schnell">FLUX-schnell</option>
<option value="Dall-E-3">Dall-E-3</option>
</select>
</div>
<div>
<label for="voice-generator" class="block text-sm font-medium mb-1">Voice Generator</label>
<select id="voice-generator" class="w-full px-4 py-2 rounded-md border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-700 text-base">
<option value="ElevenLabs">ElevenLabs</option>
<option value="PlayAI-Dialog">PlayAI-Dialog</option>
</select>
</div>
</div>
<div>
<label for="voice-name" class="block text-sm font-medium mb-1">Voice Name (Optional)</label>
<input type="text" id="voice-name" placeholder="E.g., Sarah, Brian, Lily, Monika Sogam" class="w-full px-4 py-2 rounded-md border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-700 text-base">
</div>
<button id="generate-btn" class="mt-6 w-full bg-primary hover:bg-opacity-90 text-white py-3 px-4 rounded-md font-medium transition duration-200">
Generate Video
</button>
</div>
<div id="loading-container" class="hidden flex-col items-center justify-center py-8">
<div class="loading-spinner mb-4"></div>
<div id="status-message" class="text-lg font-medium">Generating content...</div>
<div id="progress-detail" class="text-sm text-gray-500 dark:text-gray-400 mt-2"></div>
</div>
<div id="results-container" class="hidden bg-gray-100 dark:bg-gray-800 p-6 rounded-lg shadow-md">
<h2 class="text-xl font-bold mb-3">Generated Video</h2>
<div id="video-player-container" class="mb-6 relative pt-[56.25%]">
<video id="video-player" controls class="absolute top-0 left-0 w-full h-full rounded-lg">
Your browser does not support the video tag.
</video>
</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<div>
<h3 class="font-medium mb-2">Title</h3>
<p id="video-title" class="bg-white dark:bg-gray-700 p-3 rounded-md"></p>
</div>
<div>
<h3 class="font-medium mb-2">Description</h3>
<p id="video-description" class="bg-white dark:bg-gray-700 p-3 rounded-md h-24 overflow-y-auto"></p>
</div>
</div>
</div>
</div>
<script>
// Initialize dark mode based on user preference
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
document.documentElement.classList.add('dark');
}
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
if (event.matches) {
document.documentElement.classList.add('dark');
} else {
document.documentElement.classList.remove('dark');
}
});
// Handler for generating videos
document.getElementById('generate-btn').addEventListener('click', async function() {
// Get input values
const niche = document.getElementById('niche').value.trim();
const language = document.getElementById('language').value;
const textGenerator = document.getElementById('text-generator').value;
const imageGenerator = document.getElementById('image-generator').value;
const voiceGenerator = document.getElementById('voice-generator').value;
const voiceName = document.getElementById('voice-name').value.trim();
// Validation
if (!niche) {
alert('Please enter a niche/topic');
return;
}
// Show loading state
document.getElementById('loading-container').classList.remove('hidden');
document.getElementById('loading-container').classList.add('flex');
document.getElementById('results-container').classList.add('hidden');
try {
// Updates for the loading message
updateProgress('Generating topic...');
await new Promise(resolve => setTimeout(resolve, 1000));
// Step 1: Generate topic
const topic = await generateTopic(niche, textGenerator);
// Step 2: Generate script
updateProgress('Creating script...');
const script = await generateScript(topic, language, textGenerator);
// Step 3: Generate metadata
updateProgress('Creating title and description...');
const metadata = await generateMetadata(topic, script, textGenerator);
// Step 4: Generate image prompts
updateProgress('Creating image prompts...');
const imagePrompts = await generateImagePrompts(topic, script, textGenerator);
// Step 5: Generate images
updateProgress('Generating images...');
const imageUrls = await generateImages(imagePrompts, imageGenerator);
// Step 6: Generate speech
updateProgress('Creating voiceover...');
const audioUrl = await generateSpeech(script, language, voiceGenerator, voiceName);
// Step 7: Generate video
updateProgress('Creating final video...');
const videoUrl = await generateVideo(imageUrls, audioUrl, script);
// Display results
displayResults(videoUrl, metadata.title, metadata.description);
} catch (error) {
console.error('Error:', error);
document.getElementById('status-message').textContent = 'Error generating video';
document.getElementById('progress-detail').textContent = error.message || 'An unexpected error occurred';
}
});
function updateProgress(message) {
document.getElementById('progress-detail').textContent = message;
}
// Function to generate topic based on niche
async function generateTopic(niche, textGeneratorModel) {
try {
const prompt = `Please generate a specific video idea that takes about the following topic: ${niche}. Make it exactly one sentence. Only return the topic, nothing else.`;
// Use Poe API to send user message
const handlerId = 'topic-generation-handler';
let topicResult = '';
// Register handler for response
window.Poe.registerHandler(handlerId, (result) => {
if (result.responses.length > 0) {
const response = result.responses[0];
if (response.status === 'complete') {
topicResult = response.content.trim();
}
}
});
// Send request to generate topic
await window.Poe.sendUserMessage(`@${textGeneratorModel} ${prompt}`, {
handler: handlerId,
stream: false,
openChat: false
});
// Wait for response to be complete
while (!topicResult) {
await new Promise(resolve => setTimeout(resolve, 100));
}
return topicResult;
} catch (error) {
console.error('Error generating topic:', error);
throw new Error('Failed to generate topic');
}
}
// Function to generate script based on topic
async function generateScript(topic, language, textGeneratorModel) {
try {
const prompt = `
Generate a script for youtube shorts video, depending on the subject of the video.
The script is to be returned as a string with several paragraphs.
Get straight to the point, don't start with unnecessary things like, "welcome to this video".
Obviously, the script should be related to the subject of the video.
YOU MUST NOT INCLUDE ANY TYPE OF MARKDOWN OR FORMATTING IN THE SCRIPT, NEVER USE A TITLE.
YOU MUST WRITE THE SCRIPT IN THE LANGUAGE SPECIFIED IN [LANGUAGE].
ONLY RETURN THE RAW CONTENT OF THE SCRIPT. DO NOT INCLUDE "VOICEOVER", "NARRATOR" OR SIMILAR INDICATORS.
Subject: ${topic}
Language: ${language}
`;
// Use Poe API to send user message
const handlerId = 'script-generation-handler';
let scriptResult = '';
// Register handler for response
window.Poe.registerHandler(handlerId, (result) => {
if (result.responses.length > 0) {
const response = result.responses[0];
if (response.status === 'complete') {
scriptResult = response.content.trim();
}
}
});
// Send request to generate script
await window.Poe.sendUserMessage(`@${textGeneratorModel} ${prompt}`, {
handler: handlerId,
stream: false,
openChat: false
});
// Wait for response to be complete
while (!scriptResult) {
await new Promise(resolve => setTimeout(resolve, 100));
}
return scriptResult;
} catch (error) {
console.error('Error generating script:', error);
throw new Error('Failed to generate script');
}
}
// Function to generate metadata (title and description)
async function generateMetadata(topic, script, textGeneratorModel) {
try {
const titlePrompt = `Please generate a YouTube Video Title for the following subject, including hashtags: ${topic}. Only return the title, nothing else. Limit the title under 100 characters.`;
// Use Poe API to send user message for title
const titleHandlerId = 'title-generation-handler';
let titleResult = '';
// Register handler for title response
window.Poe.registerHandler(titleHandlerId, (result) => {
if (result.responses.length > 0) {
const response = result.responses[0];
if (response.status === 'complete') {
titleResult = response.content.trim();
}
}
});
// Send request to generate title
await window.Poe.sendUserMessage(`@${textGeneratorModel} ${titlePrompt}`, {
handler: titleHandlerId,
stream: false,
openChat: false
});
// Wait for title response to be complete
while (!titleResult) {
await new Promise(resolve => setTimeout(resolve, 100));
}
// Now generate description
const descPrompt = `Please generate a YouTube Video Description for the following script: ${script}. Only return the description, nothing else.`;
// Use Poe API to send user message for description
const descHandlerId = 'desc-generation-handler';
let descResult = '';
// Register handler for description response
window.Poe.registerHandler(descHandlerId, (result) => {
if (result.responses.length > 0) {
const response = result.responses[0];
if (response.status === 'complete') {
descResult = response.content.trim();
}
}
});
// Send request to generate description
await window.Poe.sendUserMessage(`@${textGeneratorModel} ${descPrompt}`, {
handler: descHandlerId,
stream: false,
openChat: false
});
// Wait for description response to be complete
while (!descResult) {
await new Promise(resolve => setTimeout(resolve, 100));
}
return {
title: titleResult,
description: descResult
};
} catch (error) {
console.error('Error generating metadata:', error);
throw new Error('Failed to generate title and description');
}
}
// Function to generate image prompts
async function generateImagePrompts(topic, script, textGeneratorModel) {
try {
const prompt = `
Generate 5 Image Prompts for AI Image Generation,
depending on the subject of a video.
Subject: ${topic}
The image prompts are to be returned as
a JSON-Array of strings.
Each search term should consist of a full sentence,
always add the main subject of the video.
Be emotional and use interesting adjectives to make the
Image Prompt as detailed as possible.
YOU MUST ONLY RETURN THE JSON-ARRAY OF STRINGS.
YOU MUST NOT RETURN ANYTHING ELSE.
For context, here is the full text:
${script}
`;
// Use Poe API to send user message
const handlerId = 'image-prompts-handler';
let promptsResult = '';
// Register handler for response
window.Poe.registerHandler(handlerId, (result) => {
if (result.responses.length > 0) {
const response = result.responses[0];
if (response.status === 'complete') {
promptsResult = response.content.trim();
}
}
});
// Send request to generate image prompts
await window.Poe.sendUserMessage(`@${textGeneratorModel} ${prompt}`, {
handler: handlerId,
stream: false,
openChat: false
});
// Wait for response to be complete
while (!promptsResult) {
await new Promise(resolve => setTimeout(resolve, 100));
}
// Clean and parse the JSON response
const cleanedResponse = promptsResult
.replace(/```json/g, '')
.replace(/```/g, '')
.trim();
try {
return JSON.parse(cleanedResponse);
} catch (parseError) {
// If parsing fails, try to extract the array from the text
const arrayMatch = cleanedResponse.match(/\[.*\]/s);
if (arrayMatch) {
return JSON.parse(arrayMatch[0]);
}
throw new Error('Failed to parse image prompts');
}
} catch (error) {
console.error('Error generating image prompts:', error);
throw new Error('Failed to generate image prompts');
}
}
// Function to generate images based on prompts
async function generateImages(imagePrompts, imageGeneratorModel) {
try {
const imageUrls = [];
for (let i = 0; i < imagePrompts.length; i++) {
updateProgress(`Generating image ${i+1}/${imagePrompts.length}...`);
// Use Poe API to send user message
const handlerId = `image-generation-handler-${i}`;
// Register handler for response
window.Poe.registerHandler(handlerId, (result) => {
if (result.responses.length > 0) {
const response = result.responses[0];
if (response.status === 'complete' && response.attachments && response.attachments.length > 0) {
imageUrls.push(response.attachments[0].url);
}
}
});
// Send request to generate image
await window.Poe.sendUserMessage(`@${imageGeneratorModel} ${imagePrompts[i]}`, {
handler: handlerId,
stream: false,
openChat: false
});
// Wait for a short time to ensure the handler has time to receive the response
await new Promise(resolve => setTimeout(resolve, 3000));
}
// Ensure we have at least one image
if (imageUrls.length === 0) {
throw new Error('Failed to generate any images');
}
return imageUrls;
} catch (error) {
console.error('Error generating images:', error);
throw new Error('Failed to generate images');
}
}
// Function to generate speech from script
async function generateSpeech(script, language, voiceGeneratorModel, voiceName) {
try {
// Use Poe API to send user message
const handlerId = 'speech-generation-handler';
let audioUrl = null;
// Register handler for response
window.Poe.registerHandler(handlerId, (result) => {
if (result.responses.length > 0) {
const response = result.responses[0];
if (response.status === 'complete' && response.attachments && response.attachments.length > 0) {
audioUrl = response.attachments[0].url;
}
}
});
// Prepare the prompt
let prompt = script;
if (voiceName) {
prompt += ` --voice ${voiceName}`;
}
// Send request to generate speech
await window.Poe.sendUserMessage(`@${voiceGeneratorModel} ${prompt}`, {
handler: handlerId,
stream: false,
openChat: false
});
// Wait for audio URL to be available
let attempts = 0;
while (!audioUrl && attempts < 30) {
await new Promise(resolve => setTimeout(resolve, 1000));
attempts++;
}
if (!audioUrl) {
throw new Error('Failed to generate speech audio');
}
return audioUrl;
} catch (error) {
console.error('Error generating speech:', error);
throw new Error('Failed to generate speech');
}
}
// Function to generate video by combining images and audio
async function generateVideo(imageUrls, audioUrl, script) {
// Here we would normally combine everything into a video
// Since we can't actually do video processing in the browser easily,
// we'll simulate it with image slideshow and audio
try {
// Create a simulated video player that shows images as a slideshow with audio
// This is a simple mockup - in a real application, you would use a video processing service
// For this demo, we'll just return the audio URL and use the first image
// as a placeholder in the video player
// In a real implementation, this is where you would call an external video
// processing service or use a server-side component
// Simulate processing time
await new Promise(resolve => setTimeout(resolve, 3000));
// Return a mock video URL (which is just the audio URL for this demo)
return {
audioUrl: audioUrl,
imageUrls: imageUrls
};
} catch (error) {
console.error('Error generating video:', error);
throw new Error('Failed to generate video');
}
}
// Function to display results
function displayResults(videoData, title, description) {
// Hide loading container
document.getElementById('loading-container').classList.add('hidden');
document.getElementById('loading-container').classList.remove('flex');
// Show results container
document.getElementById('results-container').classList.remove('hidden');
// Set title and description
document.getElementById('video-title').textContent = title;
document.getElementById('video-description').textContent = description;
// Set up video player with images slideshow and audio
const videoPlayer = document.getElementById('video-player');
// Create a simple slideshow with the first image and audio
if (videoData.imageUrls && videoData.imageUrls.length > 0) {
// Set poster to first image
videoPlayer.setAttribute('poster', videoData.imageUrls[0]);
}
// Set audio source
videoPlayer.innerHTML = '';
const audioSource = document.createElement('source');
audioSource.src = videoData.audioUrl;
audioSource.type = 'audio/mpeg';
videoPlayer.appendChild(audioSource);
// Add text explaining this is a simulation
const textOverlay = document.createElement('div');
textOverlay.innerHTML = `
<div class="absolute inset-0 flex items-center justify-center bg-black bg-opacity-50 text-white p-4 text-center">
<div>
<p class="font-bold mb-2">Audio Preview</p>
<p class="text-sm">This is an audio preview. In a full implementation, this would be a video combining the generated images and audio.</p>
</div>
</div>
`;
videoPlayer.parentNode.appendChild(textOverlay);
// Load and play
videoPlayer.load();
}
</script>
</body>
</html> |