Spaces:
Running
Running
Download index.html from PirateKnobi/appcreator: direct link, hf CLI and curl.
- Browser
- Download file 47.9 kB
-
https://huggingface.co/spaces/PirateKnobi/appcreator/resolve/main/index.html
- Command line
-
hf download hf://spaces/PirateKnobi/appcreator/index.html
-
curl -L -o index.html https://huggingface.co/spaces/PirateKnobi/appcreator/resolve/main/index.html
47.9 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="UTF-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
| <title>AI Video Creator | Transform Images to Videos</title> | |
| <script src="https://cdn.tailwindcss.com"></script> | |
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css"> | |
| <style> | |
| .dropzone { | |
| border: 2px dashed #9CA3AF; | |
| transition: all 0.3s ease; | |
| } | |
| .dropzone.active { | |
| border-color: #3B82F6; | |
| background-color: rgba(59, 130, 246, 0.05); | |
| } | |
| .video-preview { | |
| aspect-ratio: 16/9; | |
| background-color: #1F2937; | |
| } | |
| .progress-bar { | |
| transition: width 0.3s ease; | |
| } | |
| .workspace-item { | |
| transition: all 0.2s ease; | |
| } | |
| .workspace-item:hover { | |
| transform: translateY(-2px); | |
| box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1); | |
| } | |
| .kenburns-effect { | |
| animation: kenburns 20s infinite alternate; | |
| } | |
| @keyframes kenburns { | |
| 0% { transform: scale(1); } | |
| 100% { transform: scale(1.1); } | |
| } | |
| .ai-badge { | |
| position: absolute; | |
| bottom: 10px; | |
| right: 10px; | |
| background: rgba(0,0,0,0.7); | |
| color: white; | |
| padding: 2px 8px; | |
| border-radius: 4px; | |
| font-size: 10px; | |
| } | |
| .prompt-input { | |
| min-height: 100px; | |
| resize: none; | |
| } | |
| </style> | |
| </head> | |
| <body class="bg-gray-50 min-h-screen"> | |
| <div class="container mx-auto px-4 py-6"> | |
| <!-- Header --> | |
| <header class="flex justify-between items-center mb-8"> | |
| <div> | |
| <h1 class="text-3xl font-bold text-gray-800">AI Video Creator</h1> | |
| <p class="text-gray-600">Transform images into animated videos with AI</p> | |
| </div> | |
| <div class="flex items-center space-x-4"> | |
| <button id="workspaceBtn" class="px-4 py-2 bg-white border border-gray-300 rounded-lg hover:bg-gray-50 flex items-center"> | |
| <i class="fas fa-folder-open mr-2 text-blue-500"></i> | |
| My Workspace | |
| </button> | |
| <div class="w-10 h-10 rounded-full bg-blue-500 text-white flex items-center justify-center"> | |
| <i class="fas fa-user"></i> | |
| </div> | |
| </div> | |
| </header> | |
| <div class="grid grid-cols-1 lg:grid-cols-3 gap-8"> | |
| <!-- Left Panel - Creation Tools --> | |
| <div class="lg:col-span-1 bg-white rounded-xl shadow-sm p-6"> | |
| <div class="space-y-6"> | |
| <!-- Prompt Section --> | |
| <div> | |
| <h2 class="text-xl font-semibold text-gray-800 mb-3">AI Prompt</h2> | |
| <textarea id="promptInput" class="w-full prompt-input rounded-lg border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500" placeholder="Describe the animation you want..."></textarea> | |
| <div class="flex items-center mt-2 text-sm text-gray-500"> | |
| <i class="fas fa-lightbulb mr-2 text-yellow-500"></i> | |
| <span>Example: "Make the waterfall flow and add mist effects"</span> | |
| </div> | |
| </div> | |
| <!-- Image Upload --> | |
| <div> | |
| <h2 class="text-xl font-semibold text-gray-800 mb-3">Upload Image</h2> | |
| <div id="dropzone" class="dropzone rounded-lg p-6 text-center cursor-pointer"> | |
| <div class="flex flex-col items-center justify-center space-y-3"> | |
| <i class="fas fa-cloud-upload-alt text-4xl text-blue-500"></i> | |
| <p class="text-gray-600">Drag & drop your image here</p> | |
| <p class="text-sm text-gray-500">or</p> | |
| <label for="fileInput" class="px-4 py-2 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition cursor-pointer"> | |
| Select Image | |
| </label> | |
| <input id="fileInput" type="file" accept="image/*" class="hidden"> | |
| </div> | |
| </div> | |
| <div id="fileInfo" class="mt-4 hidden"> | |
| <div class="flex items-center space-x-3"> | |
| <i class="fas fa-image text-blue-500"></i> | |
| <div class="flex-1"> | |
| <div class="flex justify-between"> | |
| <span id="fileName" class="font-medium text-gray-700 truncate"></span> | |
| <button id="removeFile" class="text-red-500 hover:text-red-700"> | |
| <i class="fas fa-times"></i> | |
| </button> | |
| </div> | |
| <div class="w-full bg-gray-200 rounded-full h-2 mt-1"> | |
| <div id="uploadProgress" class="progress-bar bg-blue-500 h-2 rounded-full" style="width: 0%"></div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Animation Settings --> | |
| <div class="space-y-4"> | |
| <h2 class="text-xl font-semibold text-gray-800">Animation Settings</h2> | |
| <!-- Style Selector --> | |
| <div> | |
| <label class="block text-sm font-medium text-gray-700 mb-2">Animation Style</label> | |
| <div class="grid grid-cols-2 gap-2"> | |
| <button class="style-option px-3 py-2 border rounded-lg text-sm hover:bg-gray-50" data-style="realistic"> | |
| <i class="fas fa-mountain mr-1"></i> Realistic | |
| </button> | |
| <button class="style-option px-3 py-2 border rounded-lg text-sm hover:bg-gray-50" data-style="fantasy"> | |
| <i class="fas fa-hat-wizard mr-1"></i> Fantasy | |
| </button> | |
| <button class="style-option px-3 py-2 border rounded-lg text-sm hover:bg-gray-50" data-style="cinematic"> | |
| <i class="fas fa-film mr-1"></i> Cinematic | |
| </button> | |
| <button class="style-option px-3 py-2 border rounded-lg text-sm hover:bg-gray-50" data-style="painting"> | |
| <i class="fas fa-palette mr-1"></i> Painting | |
| </button> | |
| </div> | |
| </div> | |
| <!-- Duration --> | |
| <div> | |
| <label class="block text-sm font-medium text-gray-700 mb-2">Duration (seconds)</label> | |
| <input id="duration" type="range" min="3" max="30" value="10" class="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer"> | |
| <div class="flex justify-between text-xs text-gray-500 mt-1"> | |
| <span>3s</span> | |
| <span id="durationValue">10s</span> | |
| <span>30s</span> | |
| </div> | |
| </div> | |
| <!-- Intensity --> | |
| <div> | |
| <label class="block text-sm font-medium text-gray-700 mb-2">Motion Intensity</label> | |
| <input id="intensity" type="range" min="1" max="5" value="3" class="w-full h-2 bg-gray-200 rounded-lg appearance-none cursor-pointer"> | |
| <div class="flex justify-between text-xs text-gray-500 mt-1"> | |
| <span>Subtle</span> | |
| <span id="intensityValue">Medium</span> | |
| <span>Strong</span> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Generate Button --> | |
| <button id="generateBtn" class="w-full py-3 px-4 bg-gradient-to-r from-blue-500 to-purple-600 text-white font-semibold rounded-lg shadow-md hover:opacity-90 transition disabled:opacity-50 disabled:cursor-not-allowed" disabled> | |
| <i class="fas fa-magic mr-2"></i> Generate AI Video | |
| </button> | |
| </div> | |
| </div> | |
| <!-- Right Panel - Preview and Export --> | |
| <div class="lg:col-span-2 space-y-6"> | |
| <!-- Preview Section --> | |
| <div class="bg-white rounded-xl shadow-sm p-6"> | |
| <div class="flex justify-between items-center mb-4"> | |
| <h2 class="text-xl font-semibold text-gray-800">Video Preview</h2> | |
| <div id="aiBadge" class="text-xs bg-blue-100 text-blue-800 px-2 py-1 rounded-full hidden"> | |
| <i class="fas fa-robot mr-1"></i> AI Generated | |
| </div> | |
| </div> | |
| <div id="previewContainer" class="video-preview rounded-lg overflow-hidden flex items-center justify-center relative"> | |
| <div id="emptyPreview" class="text-center p-6"> | |
| <i class="fas fa-image text-4xl text-gray-400 mb-3"></i> | |
| <p class="text-gray-500">Upload an image and enter a prompt to create your AI video</p> | |
| </div> | |
| <img id="imagePreview" class="absolute inset-0 w-full h-full object-cover hidden kenburns-effect"> | |
| <video id="videoPreview" controls class="absolute inset-0 w-full h-full hidden"></video> | |
| <canvas id="canvasPreview" class="absolute inset-0 w-full h-full hidden"></canvas> | |
| </div> | |
| </div> | |
| <!-- Export Section --> | |
| <div id="exportSection" class="bg-white rounded-xl shadow-sm p-6 hidden"> | |
| <h2 class="text-xl font-semibold text-gray-800 mb-4">Export & Save</h2> | |
| <div class="grid grid-cols-2 md:grid-cols-4 gap-4"> | |
| <button id="downloadMp4Btn" class="py-2 px-3 bg-blue-500 text-white rounded-lg hover:bg-blue-600 transition flex flex-col items-center"> | |
| <i class="fas fa-file-video text-xl mb-1"></i> | |
| <span class="text-sm">MP4</span> | |
| </button> | |
| <button id="downloadGifBtn" class="py-2 px-3 bg-purple-500 text-white rounded-lg hover:bg-purple-600 transition flex flex-col items-center"> | |
| <i class="fas fa-file-image text-xl mb-1"></i> | |
| <span class="text-sm">GIF</span> | |
| </button> | |
| <button id="saveWorkspaceBtn" class="py-2 px-3 bg-green-500 text-white rounded-lg hover:bg-green-600 transition flex flex-col items-center"> | |
| <i class="fas fa-save text-xl mb-1"></i> | |
| <span class="text-sm">Save</span> | |
| </button> | |
| <button id="shareBtn" class="py-2 px-3 bg-pink-500 text-white rounded-lg hover:bg-pink-600 transition flex flex-col items-center"> | |
| <i class="fas fa-share-alt text-xl mb-1"></i> | |
| <span class="text-sm">Share</span> | |
| </button> | |
| </div> | |
| </div> | |
| <!-- Processing Section --> | |
| <div id="processingSection" class="bg-white rounded-xl shadow-sm p-6 hidden"> | |
| <h2 class="text-xl font-semibold text-gray-800 mb-4">AI is Creating Your Video</h2> | |
| <div class="space-y-4"> | |
| <div class="flex items-center space-x-4"> | |
| <div class="w-12 h-12 rounded-full bg-blue-100 flex items-center justify-center animate-pulse"> | |
| <i class="fas fa-robot text-blue-500 text-xl"></i> | |
| </div> | |
| <div class="flex-1"> | |
| <p class="font-medium text-gray-700" id="processingStatus">Analyzing your image and prompt...</p> | |
| <div class="w-full bg-gray-200 rounded-full h-2 mt-1"> | |
| <div id="processingProgress" class="progress-bar bg-blue-500 h-2 rounded-full" style="width: 0%"></div> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="text-sm text-gray-500"> | |
| <p id="processingTime">Estimated time remaining: 20 seconds</p> | |
| <p class="mt-1 text-xs italic" id="aiThinking">"I'm analyzing the composition of your image..."</p> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- AI Suggestions --> | |
| <div id="suggestionsSection" class="bg-white rounded-xl shadow-sm p-6 hidden"> | |
| <h2 class="text-xl font-semibold text-gray-800 mb-4">AI Suggestions</h2> | |
| <div class="space-y-3"> | |
| <div class="p-3 bg-blue-50 rounded-lg"> | |
| <p class="text-sm text-blue-800">"Try adding 'with flowing water and rustling leaves' to make the scene more dynamic"</p> | |
| </div> | |
| <div class="p-3 bg-purple-50 rounded-lg"> | |
| <p class="text-sm text-purple-800">"For a cinematic look, consider 'soft focus with lens flare effects'"</p> | |
| </div> | |
| <button class="w-full mt-2 py-2 px-4 bg-white border border-gray-300 text-gray-700 font-medium rounded-lg hover:bg-gray-50 transition"> | |
| <i class="fas fa-sync-alt mr-2"></i> Get More Suggestions | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| <!-- Workspace Modal --> | |
| <div id="workspaceModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 z-50 hidden"> | |
| <div class="bg-white rounded-xl shadow-lg w-full max-w-4xl max-h-[90vh] overflow-hidden"> | |
| <div class="flex justify-between items-center border-b p-4"> | |
| <h3 class="text-xl font-semibold text-gray-800">My Workspace</h3> | |
| <button id="closeWorkspaceBtn" class="text-gray-500 hover:text-gray-700"> | |
| <i class="fas fa-times"></i> | |
| </button> | |
| </div> | |
| <div class="p-4 overflow-y-auto max-h-[70vh]"> | |
| <div id="workspaceGrid" class="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4"> | |
| <!-- Workspace items will be added here dynamically --> | |
| <div class="text-center py-10 text-gray-500" id="emptyWorkspace"> | |
| <i class="fas fa-folder-open text-4xl mb-3"></i> | |
| <p>Your workspace is empty</p> | |
| <p class="text-sm mt-1">Create and save videos to see them here</p> | |
| </div> | |
| </div> | |
| </div> | |
| <div class="border-t p-4 flex justify-end"> | |
| <button id="clearWorkspaceBtn" class="px-4 py-2 bg-red-500 text-white rounded-lg hover:bg-red-600 transition"> | |
| <i class="fas fa-trash mr-2"></i> Clear Workspace | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| <script> | |
| document.addEventListener('DOMContentLoaded', function() { | |
| // DOM Elements | |
| const dropzone = document.getElementById('dropzone'); | |
| const fileInput = document.getElementById('fileInput'); | |
| const fileInfo = document.getElementById('fileInfo'); | |
| const fileName = document.getElementById('fileName'); | |
| const removeFile = document.getElementById('removeFile'); | |
| const uploadProgress = document.getElementById('uploadProgress'); | |
| const generateBtn = document.getElementById('generateBtn'); | |
| const emptyPreview = document.getElementById('emptyPreview'); | |
| const imagePreview = document.getElementById('imagePreview'); | |
| const videoPreview = document.getElementById('videoPreview'); | |
| const canvasPreview = document.getElementById('canvasPreview'); | |
| const previewContainer = document.getElementById('previewContainer'); | |
| const exportSection = document.getElementById('exportSection'); | |
| const processingSection = document.getElementById('processingSection'); | |
| const processingProgress = document.getElementById('processingProgress'); | |
| const processingStatus = document.getElementById('processingStatus'); | |
| const processingTime = document.getElementById('processingTime'); | |
| const aiThinking = document.getElementById('aiThinking'); | |
| const downloadMp4Btn = document.getElementById('downloadMp4Btn'); | |
| const downloadGifBtn = document.getElementById('downloadGifBtn'); | |
| const saveWorkspaceBtn = document.getElementById('saveWorkspaceBtn'); | |
| const shareBtn = document.getElementById('shareBtn'); | |
| const promptInput = document.getElementById('promptInput'); | |
| const duration = document.getElementById('duration'); | |
| const durationValue = document.getElementById('durationValue'); | |
| const intensity = document.getElementById('intensity'); | |
| const intensityValue = document.getElementById('intensityValue'); | |
| const aiBadge = document.getElementById('aiBadge'); | |
| const suggestionsSection = document.getElementById('suggestionsSection'); | |
| const styleOptions = document.querySelectorAll('.style-option'); | |
| const workspaceBtn = document.getElementById('workspaceBtn'); | |
| const workspaceModal = document.getElementById('workspaceModal'); | |
| const closeWorkspaceBtn = document.getElementById('closeWorkspaceBtn'); | |
| const workspaceGrid = document.getElementById('workspaceGrid'); | |
| const emptyWorkspace = document.getElementById('emptyWorkspace'); | |
| const clearWorkspaceBtn = document.getElementById('clearWorkspaceBtn'); | |
| // Variables | |
| let uploadedFile = null; | |
| let videoBlob = null; | |
| let gifBlob = null; | |
| let mediaRecorder = null; | |
| let chunks = []; | |
| let selectedStyle = 'realistic'; | |
| let motionIntensity = 3; | |
| let workspaceItems = JSON.parse(localStorage.getItem('aiVideoWorkspace')) || []; | |
| let currentProject = null; | |
| // Animation messages | |
| const aiMessages = [ | |
| "Analyzing image composition...", | |
| "Interpreting your creative prompt...", | |
| "Generating motion paths...", | |
| "Applying ${selectedStyle} effects...", | |
| "Rendering animation frames...", | |
| "Finalizing video output..." | |
| ]; | |
| const intensityLabels = ['Subtle', 'Light', 'Medium', 'Strong', 'Extreme']; | |
| // Event Listeners | |
| dropzone.addEventListener('click', () => fileInput.click()); | |
| fileInput.addEventListener('change', handleFileSelect); | |
| dropzone.addEventListener('dragover', (e) => { | |
| e.preventDefault(); | |
| dropzone.classList.add('active'); | |
| }); | |
| dropzone.addEventListener('dragleave', () => { | |
| dropzone.classList.remove('active'); | |
| }); | |
| dropzone.addEventListener('drop', (e) => { | |
| e.preventDefault(); | |
| dropzone.classList.remove('active'); | |
| if (e.dataTransfer.files.length) { | |
| fileInput.files = e.dataTransfer.files; | |
| handleFileSelect({ target: fileInput }); | |
| } | |
| }); | |
| removeFile.addEventListener('click', resetFileUpload); | |
| generateBtn.addEventListener('click', generateVideo); | |
| downloadMp4Btn.addEventListener('click', downloadVideo); | |
| downloadGifBtn.addEventListener('click', downloadGif); | |
| saveWorkspaceBtn.addEventListener('click', saveToWorkspace); | |
| shareBtn.addEventListener('click', shareVideo); | |
| promptInput.addEventListener('input', checkGenerateButton); | |
| duration.addEventListener('input', updateDurationValue); | |
| intensity.addEventListener('input', updateIntensityValue); | |
| // Style selection | |
| styleOptions.forEach(option => { | |
| option.addEventListener('click', function() { | |
| styleOptions.forEach(opt => opt.classList.remove('border-blue-500', 'bg-blue-50')); | |
| this.classList.add('border-blue-500', 'bg-blue-50'); | |
| selectedStyle = this.dataset.style; | |
| }); | |
| }); | |
| // Workspace | |
| workspaceBtn.addEventListener('click', openWorkspace); | |
| closeWorkspaceBtn.addEventListener('click', closeWorkspace); | |
| clearWorkspaceBtn.addEventListener('click', clearWorkspace); | |
| // Initialize | |
| updateDurationValue(); | |
| updateIntensityValue(); | |
| styleOptions[0].classList.add('border-blue-500', 'bg-blue-50'); | |
| renderWorkspace(); | |
| // Functions | |
| function handleFileSelect(e) { | |
| const file = e.target.files[0]; | |
| if (!file) return; | |
| if (!file.type.match('image.*')) { | |
| alert('Please select an image file (JPEG, PNG, etc.)'); | |
| return; | |
| } | |
| uploadedFile = file; | |
| fileName.textContent = file.name; | |
| fileInfo.classList.remove('hidden'); | |
| // Simulate upload progress | |
| let progress = 0; | |
| const interval = setInterval(() => { | |
| progress += 5; | |
| uploadProgress.style.width = `${progress}%`; | |
| if (progress >= 100) { | |
| clearInterval(interval); | |
| previewImage(file); | |
| } | |
| }, 50); | |
| } | |
| function previewImage(file) { | |
| const reader = new FileReader(); | |
| reader.onload = function(e) { | |
| emptyPreview.classList.add('hidden'); | |
| imagePreview.classList.remove('hidden'); | |
| videoPreview.classList.add('hidden'); | |
| canvasPreview.classList.add('hidden'); | |
| imagePreview.src = e.target.result; | |
| checkGenerateButton(); | |
| }; | |
| reader.readAsDataURL(file); | |
| } | |
| function checkGenerateButton() { | |
| generateBtn.disabled = !(uploadedFile && promptInput.value.trim().length > 5); | |
| } | |
| function resetFileUpload() { | |
| fileInput.value = ''; | |
| uploadedFile = null; | |
| fileInfo.classList.add('hidden'); | |
| emptyPreview.classList.remove('hidden'); | |
| imagePreview.classList.add('hidden'); | |
| videoPreview.classList.add('hidden'); | |
| canvasPreview.classList.add('hidden'); | |
| uploadProgress.style.width = '0%'; | |
| checkGenerateButton(); | |
| } | |
| function generateVideo() { | |
| if (!uploadedFile || !promptInput.value.trim()) return; | |
| // Show processing section | |
| processingSection.classList.remove('hidden'); | |
| exportSection.classList.add('hidden'); | |
| suggestionsSection.classList.add('hidden'); | |
| videoPreview.classList.add('hidden'); | |
| imagePreview.classList.add('hidden'); | |
| canvasPreview.classList.remove('hidden'); | |
| aiBadge.classList.remove('hidden'); | |
| // Create project object | |
| currentProject = { | |
| id: Date.now(), | |
| prompt: promptInput.value.trim(), | |
| style: selectedStyle, | |
| intensity: motionIntensity, | |
| duration: parseInt(duration.value), | |
| image: imagePreview.src, | |
| createdAt: new Date().toISOString() | |
| }; | |
| // Start the AI processing simulation | |
| simulateAIProcessing(); | |
| } | |
| function simulateAIProcessing() { | |
| let progress = 0; | |
| const totalDuration = parseInt(duration.value) * 1000; | |
| const steps = aiMessages.length; | |
| const stepDuration = totalDuration / steps; | |
| let currentStep = 0; | |
| const interval = setInterval(() => { | |
| if (currentStep < steps) { | |
| progress = Math.round(((currentStep + 1) / steps) * 100); | |
| processingProgress.style.width = `${progress}%`; | |
| // Update status with interpolated message | |
| const message = aiMessages[currentStep].replace('${selectedStyle}', selectedStyle); | |
| processingStatus.textContent = message; | |
| // Show "AI thinking" messages | |
| if (currentStep % 2 === 0) { | |
| showAIThinkingMessage(); | |
| } | |
| // Update estimated time | |
| const remaining = Math.round((totalDuration - (currentStep * stepDuration)) / 1000); | |
| processingTime.textContent = `Estimated time remaining: ${remaining} seconds`; | |
| // Update the canvas with "AI generation" effect | |
| updateAICanvas(currentStep / steps); | |
| currentStep++; | |
| } else { | |
| clearInterval(interval); | |
| processingComplete(); | |
| } | |
| }, stepDuration); | |
| } | |
| function showAIThinkingMessage() { | |
| const thoughts = [ | |
| "Adding special effects based on your style preference...", | |
| "Creating depth and parallax effects...", | |
| "Enhancing colors for a more vibrant look...", | |
| "Analyzing composition for optimal movement...", | |
| "Applying ${selectedStyle} style filters..." | |
| ]; | |
| const randomThought = thoughts[Math.floor(Math.random() * thoughts.length)] | |
| .replace('${selectedStyle}', selectedStyle); | |
| aiThinking.textContent = `"${randomThought}"`; | |
| } | |
| function updateAICanvas(progress) { | |
| const ctx = canvasPreview.getContext('2d'); | |
| canvasPreview.width = previewContainer.clientWidth; | |
| canvasPreview.height = previewContainer.clientHeight; | |
| // Clear canvas | |
| ctx.clearRect(0, 0, canvasPreview.width, canvasPreview.height); | |
| // Draw original image (faded) | |
| const img = new Image(); | |
| img.src = imagePreview.src; | |
| ctx.globalAlpha = 0.7; | |
| ctx.drawImage(img, 0, 0, canvasPreview.width, canvasPreview.height); | |
| // Add AI processing effects based on progress | |
| ctx.globalAlpha = 0.5; | |
| // Style-specific effects | |
| if (selectedStyle === 'fantasy') { | |
| // Add magical particles | |
| for (let i = 0; i < 20 * progress * motionIntensity; i++) { | |
| const x = Math.random() * canvasPreview.width; | |
| const y = Math.random() * canvasPreview.height; | |
| const size = 2 + Math.random() * 4; | |
| const hue = 200 + Math.random() * 160; | |
| ctx.fillStyle = `hsla(${hue}, 100%, 70%, ${0.3 + Math.random() * 0.7})`; | |
| ctx.beginPath(); | |
| ctx.arc(x, y, size, 0, Math.PI * 2); | |
| ctx.fill(); | |
| } | |
| } else if (selectedStyle === 'cinematic') { | |
| // Add cinematic effects | |
| const gradient = ctx.createLinearGradient(0, 0, canvasPreview.width, 0); | |
| gradient.addColorStop(0, 'rgba(0,0,0,0.2)'); | |
| gradient.addColorStop(0.5, 'transparent'); | |
| gradient.addColorStop(1, 'rgba(0,0,0,0.2)'); | |
| ctx.fillStyle = gradient; | |
| ctx.fillRect(0, 0, canvasPreview.width, canvasPreview.height); | |
| // Lens flare effect | |
| if (progress > 0.5) { | |
| const flareX = canvasPreview.width * 0.7; | |
| const flareY = canvasPreview.height * 0.3; | |
| const flareSize = 50 + progress * 50; | |
| const flareGradient = ctx.createRadialGradient( | |
| flareX, flareY, 0, | |
| flareX, flareY, flareSize | |
| ); | |
| flareGradient.addColorStop(0, 'rgba(255,255,255,0.8)'); | |
| flareGradient.addColorStop(1, 'rgba(255,255,255,0)'); | |
| ctx.fillStyle = flareGradient; | |
| ctx.fillRect(0, 0, canvasPreview.width, canvasPreview.height); | |
| } | |
| } | |
| // Add progress text | |
| ctx.globalAlpha = 1; | |
| ctx.fillStyle = 'white'; | |
| ctx.font = 'bold 16px Arial'; | |
| ctx.textAlign = 'center'; | |
| ctx.fillText(`AI Generating: ${Math.round(progress * 100)}%`, canvasPreview.width / 2, canvasPreview.height - 30); | |
| } | |
| function processingComplete() { | |
| processingSection.classList.add('hidden'); | |
| exportSection.classList.remove('hidden'); | |
| suggestionsSection.classList.remove('hidden'); | |
| canvasPreview.classList.add('hidden'); | |
| videoPreview.classList.remove('hidden'); | |
| // Create the final video | |
| createAIVideo(); | |
| } | |
| function createAIVideo() { | |
| // Create a canvas to generate our demo video | |
| const canvas = document.createElement('canvas'); | |
| const ctx = canvas.getContext('2d'); | |
| canvas.width = 1280; | |
| canvas.height = 720; | |
| const img = new Image(); | |
| img.onload = function() { | |
| // Create a stream from our canvas | |
| const stream = canvas.captureStream(30); | |
| mediaRecorder = new MediaRecorder(stream, { mimeType: 'video/webm' }); | |
| chunks = []; | |
| mediaRecorder.ondataavailable = function(e) { | |
| chunks.push(e.data); | |
| }; | |
| mediaRecorder.onstop = function() { | |
| videoBlob = new Blob(chunks, { type: 'video/mp4' }); | |
| videoPreview.src = URL.createObjectURL(videoBlob); | |
| // Save video URL to current project | |
| currentProject.videoUrl = URL.createObjectURL(videoBlob); | |
| // Also create a GIF version | |
| createGifVersion(canvas, img); | |
| }; | |
| // Start recording | |
| mediaRecorder.start(); | |
| // Animate based on prompt and style | |
| const durationMs = parseInt(duration.value) * 1000; | |
| const startTime = Date.now(); | |
| const endTime = startTime + durationMs; | |
| function animate() { | |
| const now = Date.now(); | |
| const progress = Math.min(1, (now - startTime) / durationMs); | |
| // Clear canvas | |
| ctx.clearRect(0, 0, canvas.width, canvas.height); | |
| // Apply style-specific animations | |
| applyStyleAnimation(ctx, img, canvas.width, canvas.height, progress); | |
| if (now < endTime) { | |
| requestAnimationFrame(animate); | |
| } else { | |
| mediaRecorder.stop(); | |
| } | |
| } | |
| animate(); | |
| }; | |
| img.src = imagePreview.src; | |
| } | |
| function applyStyleAnimation(ctx, img, width, height, progress) { | |
| const scale = Math.max(width / img.width, height / img.height); | |
| let x = (width - img.width * scale) / 2; | |
| let y = (height - img.height * scale) / 2; | |
| // Base animation based on style and intensity | |
| const intensityFactor = motionIntensity / 3; // Normalize to 1 | |
| switch(selectedStyle) { | |
| case 'realistic': | |
| // Subtle natural movements | |
| x += Math.sin(progress * Math.PI * 2) * 10 * intensityFactor; | |
| y += Math.cos(progress * Math.PI) * 5 * intensityFactor; | |
| break; | |
| case 'fantasy': | |
| // Magical floating effect | |
| y += Math.sin(progress * Math.PI * 4) * 20 * intensityFactor; | |
| // Add magical particles | |
| for (let i = 0; i < 30 * intensityFactor; i++) { | |
| const px = Math.random() * width; | |
| const py = Math.random() * height; | |
| const size = 2 + Math.random() * 5; | |
| const hue = 200 + Math.random() * 160; | |
| ctx.fillStyle = `hsla(${hue}, 100%, 70%, ${0.3 + Math.random() * 0.7})`; | |
| ctx.beginPath(); | |
| ctx.arc(px, py, size, 0, Math.PI * 2); | |
| ctx.fill(); | |
| } | |
| break; | |
| case 'cinematic': | |
| // Slow zoom with parallax | |
| const zoom = 0.1 * progress * intensityFactor; | |
| x = (width - img.width * scale * (1 + zoom)) / 2; | |
| y = (height - img.height * scale * (1 + zoom)) / 2; | |
| // Add vignette | |
| const gradient = ctx.createRadialGradient( | |
| width/2, height/2, height*0.4, | |
| width/2, height/2, height*0.8 | |
| ); | |
| gradient.addColorStop(0, 'rgba(0,0,0,0)'); | |
| gradient.addColorStop(1, 'rgba(0,0,0,0.5)'); | |
| ctx.fillStyle = gradient; | |
| ctx.fillRect(0, 0, width, height); | |
| break; | |
| case 'painting': | |
| // Brush stroke effect | |
| ctx.globalAlpha = 0.9; | |
| if (progress > 0.5) { | |
| ctx.filter = `blur(${intensityFactor}px)`; | |
| } | |
| break; | |
| } | |
| // Draw the image with current animation | |
| ctx.drawImage(img, x, y, img.width * scale, img.height * scale); | |
| // Reset context | |
| ctx.globalAlpha = 1; | |
| ctx.filter = 'none'; | |
| } | |
| function createGifVersion(canvas, img) { | |
| // This is a simplified version - in a real app you'd use a GIF encoder library | |
| const gifStream = canvas.captureStream(15); | |
| const gifRecorder = new MediaRecorder(gifStream, { mimeType: 'video/webm' }); | |
| const gifChunks = []; | |
| gifRecorder.ondataavailable = function(e) { | |
| gifChunks.push(e.data); | |
| }; | |
| gifRecorder.onstop = function() { | |
| gifBlob = new Blob(gifChunks, { type: 'image/gif' }); | |
| // Save GIF URL to current project | |
| currentProject.gifUrl = URL.createObjectURL(gifBlob); | |
| }; | |
| // Start recording for GIF | |
| gifRecorder.start(); | |
| // Stop after 1 second (demo only) | |
| setTimeout(() => gifRecorder.stop(), 1000); | |
| } | |
| function downloadVideo() { | |
| if (!videoBlob) return; | |
| const a = document.createElement('a'); | |
| a.href = URL.createObjectURL(videoBlob); | |
| a.download = `ai-video-${new Date().getTime()}.mp4`; | |
| document.body.appendChild(a); | |
| a.click(); | |
| document.body.removeChild(a); | |
| } | |
| function downloadGif() { | |
| if (!gifBlob) return; | |
| const a = document.createElement('a'); | |
| a.href = URL.createObjectURL(gifBlob); | |
| a.download = `ai-animation-${new Date().getTime()}.gif`; | |
| document.body.appendChild(a); | |
| a.click(); | |
| document.body.removeChild(a); | |
| } | |
| function saveToWorkspace() { | |
| if (!currentProject) return; | |
| // Add to workspace | |
| workspaceItems.unshift(currentProject); | |
| localStorage.setItem('aiVideoWorkspace', JSON.stringify(workspaceItems)); | |
| // Show success message | |
| alert('Project saved to your workspace!'); | |
| // Update workspace display | |
| renderWorkspace(); | |
| } | |
| function shareVideo() { | |
| if (!videoBlob) return; | |
| // In a real app, this would use the Web Share API or social media SDKs | |
| alert('Share functionality would be implemented here. In a real app, this would allow sharing to social media or via email.'); | |
| } | |
| function updateDurationValue() { | |
| durationValue.textContent = `${duration.value}s`; | |
| } | |
| function updateIntensityValue() { | |
| motionIntensity = parseInt(intensity.value); | |
| intensityValue.textContent = intensityLabels[motionIntensity - 1]; | |
| } | |
| // Workspace Functions | |
| function openWorkspace() { | |
| workspaceModal.classList.remove('hidden'); | |
| } | |
| function closeWorkspace() { | |
| workspaceModal.classList.add('hidden'); | |
| } | |
| function clearWorkspace() { | |
| if (confirm('Are you sure you want to clear your workspace? This cannot be undone.')) { | |
| workspaceItems = []; | |
| localStorage.setItem('aiVideoWorkspace', JSON.stringify(workspaceItems)); | |
| renderWorkspace(); | |
| } | |
| } | |
| function renderWorkspace() { | |
| workspaceGrid.innerHTML = ''; | |
| if (workspaceItems.length === 0) { | |
| emptyWorkspace.classList.remove('hidden'); | |
| return; | |
| } | |
| emptyWorkspace.classList.add('hidden'); | |
| workspaceItems.forEach((project, index) => { | |
| const projectElement = document.createElement('div'); | |
| projectElement.className = 'workspace-item bg-white rounded-lg overflow-hidden shadow-sm border border-gray-200 cursor-pointer'; | |
| projectElement.innerHTML = ` | |
| <div class="relative pt-[56.25%]"> | |
| <img src="${project.image}" class="absolute inset-0 w-full h-full object-cover"> | |
| <div class="ai-badge"> | |
| <i class="fas fa-robot mr-1"></i> ${project.style} | |
| </div> | |
| </div> | |
| <div class="p-3"> | |
| <h4 class="font-medium text-gray-800 truncate">${project.prompt}</h4> | |
| <div class="flex justify-between items-center mt-2 text-xs text-gray-500"> | |
| <span>${new Date(project.createdAt).toLocaleDateString()}</span> | |
| <div class="flex space-x-2"> | |
| <button class="text-blue-500 hover:text-blue-700 edit-project" data-id="${project.id}"> | |
| <i class="fas fa-edit"></i> | |
| </button> | |
| <button class="text-red-500 hover:text-red-700 delete-project" data-id="${project.id}"> | |
| <i class="fas fa-trash"></i> | |
| </button> | |
| </div> | |
| </div> | |
| </div> | |
| `; | |
| workspaceGrid.appendChild(projectElement); | |
| // Add event listeners to the new buttons | |
| projectElement.querySelector('.edit-project').addEventListener('click', (e) => { | |
| e.stopPropagation(); | |
| editProject(project.id); | |
| }); | |
| projectElement.querySelector('.delete-project').addEventListener('click', (e) => { | |
| e.stopPropagation(); | |
| deleteProject(project.id); | |
| }); | |
| projectElement.addEventListener('click', () => openProject(project.id)); | |
| }); | |
| } | |
| function openProject(id) { | |
| const project = workspaceItems.find(p => p.id === id); | |
| if (!project) return; | |
| // Load project into editor | |
| promptInput.value = project.prompt; | |
| duration.value = project.duration; | |
| updateDurationValue(); | |
| intensity.value = project.intensity; | |
| updateIntensityValue(); | |
| // Set style | |
| styleOptions.forEach(opt => opt.classList.remove('border-blue-500', 'bg-blue-50')); | |
| const styleBtn = document.querySelector(`.style-option[data-style="${project.style}"]`); | |
| if (styleBtn) styleBtn.classList.add('border-blue-500', 'bg-blue-50'); | |
| selectedStyle = project.style; | |
| // Load image | |
| imagePreview.src = project.image; | |
| imagePreview.classList.remove('hidden'); | |
| emptyPreview.classList.add('hidden'); | |
| // Load video if available | |
| if (project.videoUrl) { | |
| videoPreview.src = project.videoUrl; | |
| videoPreview.classList.remove('hidden'); | |
| exportSection.classList.remove('hidden'); | |
| aiBadge.classList.remove('hidden'); | |
| } else { | |
| videoPreview.classList.add('hidden'); | |
| exportSection.classList.add('hidden'); | |
| } | |
| // Set as current project | |
| currentProject = project; | |
| // Close workspace | |
| closeWorkspace(); | |
| // Scroll to top | |
| window.scrollTo(0, 0); | |
| } | |
| function editProject(id) { | |
| const project = workspaceItems.find(p => p.id === id); | |
| if (!project) return; | |
| const newPrompt = prompt('Edit your prompt:', project.prompt); | |
| if (newPrompt !== null) { | |
| project.prompt = newPrompt; | |
| localStorage.setItem('aiVideoWorkspace', JSON.stringify(workspaceItems)); | |
| renderWorkspace(); | |
| } | |
| } | |
| function deleteProject(id) { | |
| if (confirm('Are you sure you want to delete this project?')) { | |
| workspaceItems = workspaceItems.filter(p => p.id !== id); | |
| localStorage.setItem('aiVideoWorkspace', JSON.stringify(workspaceItems)); | |
| renderWorkspace(); | |
| } | |
| } | |
| }); | |
| </script> | |
| <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=PirateKnobi/appcreator" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body> | |
| </html> |