Spaces:
Running
Running
use motionmuse.ai like engine for free to make the operation going
Browse files- components/motionmuse-integration.js +51 -0
- index.html +1 -0
- script.js +77 -12
- style.css +12 -0
components/motionmuse-integration.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
class MotionMuseIntegration extends HTMLElement {
|
| 2 |
+
constructor() {
|
| 3 |
+
super();
|
| 4 |
+
this.apiKey = 'free_tier_key'; // Replace with actual free tier key
|
| 5 |
+
this.baseUrl = 'https://api.motionmuse.ai/v1';
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
async generateAnimation(imageData, options = {}) {
|
| 9 |
+
try {
|
| 10 |
+
const response = await fetch(`${this.baseUrl}/animate`, {
|
| 11 |
+
method: 'POST',
|
| 12 |
+
headers: {
|
| 13 |
+
'Content-Type': 'application/json',
|
| 14 |
+
'Authorization': `Bearer ${this.apiKey}`
|
| 15 |
+
},
|
| 16 |
+
body: JSON.stringify({
|
| 17 |
+
image: imageData,
|
| 18 |
+
duration: options.duration || 10,
|
| 19 |
+
style: options.style || 'realistic',
|
| 20 |
+
music: options.music || false,
|
| 21 |
+
nsfw: true
|
| 22 |
+
})
|
| 23 |
+
});
|
| 24 |
+
|
| 25 |
+
if (!response.ok) {
|
| 26 |
+
throw new Error('Animation generation failed');
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
return await response.json();
|
| 30 |
+
} catch (error) {
|
| 31 |
+
console.error('MotionMuse API error:', error);
|
| 32 |
+
throw error;
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
async getStatus(jobId) {
|
| 37 |
+
try {
|
| 38 |
+
const response = await fetch(`${this.baseUrl}/status/${jobId}`, {
|
| 39 |
+
headers: {
|
| 40 |
+
'Authorization': `Bearer ${this.apiKey}`
|
| 41 |
+
}
|
| 42 |
+
});
|
| 43 |
+
return await response.json();
|
| 44 |
+
} catch (error) {
|
| 45 |
+
console.error('Status check error:', error);
|
| 46 |
+
throw error;
|
| 47 |
+
}
|
| 48 |
+
}
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
customElements.define('motionmuse-integration', MotionMuseIntegration);
|
index.html
CHANGED
|
@@ -11,6 +11,7 @@
|
|
| 11 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>
|
| 12 |
<script src="components/navbar.js"></script>
|
| 13 |
<script src="components/footer.js"></script>
|
|
|
|
| 14 |
</head>
|
| 15 |
<body class="bg-gray-900 text-white min-h-screen flex flex-col">
|
| 16 |
<nsfw-warning></nsfw-warning>
|
|
|
|
| 11 |
<script src="https://cdnjs.cloudflare.com/ajax/libs/gsap/3.12.2/gsap.min.js"></script>
|
| 12 |
<script src="components/navbar.js"></script>
|
| 13 |
<script src="components/footer.js"></script>
|
| 14 |
+
<script src="components/motionmuse-integration.js"></script>
|
| 15 |
</head>
|
| 16 |
<body class="bg-gray-900 text-white min-h-screen flex flex-col">
|
| 17 |
<nsfw-warning></nsfw-warning>
|
script.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
|
|
| 1 |
// Shared functionality across pages
|
| 2 |
-
document.addEventListener('DOMContentLoaded', () => {
|
| 3 |
-
// Initialize
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
const tooltipElements = document.querySelectorAll('[data-tooltip]');
|
| 5 |
tooltipElements.forEach(el => {
|
| 6 |
const tooltip = document.createElement('div');
|
|
@@ -19,23 +24,83 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 19 |
tooltip.classList.add('hidden');
|
| 20 |
});
|
| 21 |
});
|
| 22 |
-
|
| 23 |
// Handle generate button click
|
| 24 |
const generateBtn = document.getElementById('generateBtn');
|
| 25 |
if (generateBtn) {
|
| 26 |
-
generateBtn.addEventListener('click', () => {
|
|
|
|
|
|
|
|
|
|
| 27 |
generateBtn.innerHTML = '<i data-feather="loader" class="animate-spin mr-2"></i> Generating...';
|
| 28 |
feather.replace();
|
|
|
|
| 29 |
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
feather.replace();
|
|
|
|
| 34 |
|
| 35 |
-
// Show
|
| 36 |
const toast = document.createElement('div');
|
| 37 |
-
toast.className = 'fixed bottom-4 right-4 bg-
|
| 38 |
-
toast.innerHTML = '<i data-feather="
|
| 39 |
document.body.appendChild(toast);
|
| 40 |
feather.replace();
|
| 41 |
|
|
@@ -43,7 +108,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 43 |
toast.classList.add('opacity-0', 'transition-opacity', 'duration-300');
|
| 44 |
setTimeout(() => toast.remove(), 300);
|
| 45 |
}, 3000);
|
| 46 |
-
}
|
| 47 |
-
|
| 48 |
}
|
| 49 |
});
|
|
|
|
| 1 |
+
|
| 2 |
// Shared functionality across pages
|
| 3 |
+
document.addEventListener('DOMContentLoaded', async () => {
|
| 4 |
+
// Initialize MotionMuse integration
|
| 5 |
+
const motionMuse = document.createElement('motionmuse-integration');
|
| 6 |
+
document.body.appendChild(motionMuse);
|
| 7 |
+
|
| 8 |
+
// Initialize tooltips
|
| 9 |
const tooltipElements = document.querySelectorAll('[data-tooltip]');
|
| 10 |
tooltipElements.forEach(el => {
|
| 11 |
const tooltip = document.createElement('div');
|
|
|
|
| 24 |
tooltip.classList.add('hidden');
|
| 25 |
});
|
| 26 |
});
|
|
|
|
| 27 |
// Handle generate button click
|
| 28 |
const generateBtn = document.getElementById('generateBtn');
|
| 29 |
if (generateBtn) {
|
| 30 |
+
generateBtn.addEventListener('click', async () => {
|
| 31 |
+
const imagePreview = document.getElementById('imagePreview');
|
| 32 |
+
if (!imagePreview.src) return;
|
| 33 |
+
|
| 34 |
generateBtn.innerHTML = '<i data-feather="loader" class="animate-spin mr-2"></i> Generating...';
|
| 35 |
feather.replace();
|
| 36 |
+
generateBtn.disabled = true;
|
| 37 |
|
| 38 |
+
try {
|
| 39 |
+
// Get user options
|
| 40 |
+
const style = document.querySelector('select:nth-of-type(1)').value;
|
| 41 |
+
const duration = document.querySelector('input[type="range"]').value;
|
| 42 |
+
const music = document.querySelector('select:nth-of-type(2)').value;
|
| 43 |
+
|
| 44 |
+
// Generate animation
|
| 45 |
+
const result = await motionMuse.generateAnimation(imagePreview.src, {
|
| 46 |
+
duration,
|
| 47 |
+
style,
|
| 48 |
+
music: music !== 'None'
|
| 49 |
+
});
|
| 50 |
+
|
| 51 |
+
// Poll for completion
|
| 52 |
+
const pollStatus = async () => {
|
| 53 |
+
const status = await motionMuse.getStatus(result.jobId);
|
| 54 |
+
if (status.progress === 100) {
|
| 55 |
+
// Update video preview
|
| 56 |
+
const videoPreview = document.getElementById('animationPreview');
|
| 57 |
+
videoPreview.innerHTML = `
|
| 58 |
+
<video src="${status.videoUrl}" autoplay loop muted class="w-full h-full object-cover"></video>
|
| 59 |
+
<div class="absolute inset-0 bg-gradient-to-t from-black/80 to-transparent"></div>
|
| 60 |
+
`;
|
| 61 |
+
|
| 62 |
+
generateBtn.innerHTML = '<i data-feather="download" class="mr-2"></i> Download Video';
|
| 63 |
+
feather.replace();
|
| 64 |
+
generateBtn.disabled = false;
|
| 65 |
+
|
| 66 |
+
// Show success message
|
| 67 |
+
const toast = document.createElement('div');
|
| 68 |
+
toast.className = 'fixed bottom-4 right-4 bg-green-600 text-white px-4 py-2 rounded-lg shadow-lg flex items-center';
|
| 69 |
+
toast.innerHTML = '<i data-feather="check-circle" class="mr-2"></i> Video generated successfully!';
|
| 70 |
+
document.body.appendChild(toast);
|
| 71 |
+
feather.replace();
|
| 72 |
+
|
| 73 |
+
setTimeout(() => {
|
| 74 |
+
toast.classList.add('opacity-0', 'transition-opacity', 'duration-300');
|
| 75 |
+
setTimeout(() => toast.remove(), 300);
|
| 76 |
+
}, 3000);
|
| 77 |
+
|
| 78 |
+
// Enable download
|
| 79 |
+
generateBtn.addEventListener('click', () => {
|
| 80 |
+
const a = document.createElement('a');
|
| 81 |
+
a.href = status.videoUrl;
|
| 82 |
+
a.download = 'pixflow-animation.mp4';
|
| 83 |
+
a.click();
|
| 84 |
+
});
|
| 85 |
+
} else {
|
| 86 |
+
// Update progress
|
| 87 |
+
generateBtn.innerHTML = `<i data-feather="loader" class="animate-spin mr-2"></i> Generating (${status.progress}%)`;
|
| 88 |
+
feather.replace();
|
| 89 |
+
setTimeout(pollStatus, 1500);
|
| 90 |
+
}
|
| 91 |
+
};
|
| 92 |
+
|
| 93 |
+
await pollStatus();
|
| 94 |
+
} catch (error) {
|
| 95 |
+
console.error('Generation error:', error);
|
| 96 |
+
generateBtn.innerHTML = '<i data-feather="alert-circle" class="mr-2"></i> Try Again';
|
| 97 |
feather.replace();
|
| 98 |
+
generateBtn.disabled = false;
|
| 99 |
|
| 100 |
+
// Show error message
|
| 101 |
const toast = document.createElement('div');
|
| 102 |
+
toast.className = 'fixed bottom-4 right-4 bg-red-600 text-white px-4 py-2 rounded-lg shadow-lg flex items-center';
|
| 103 |
+
toast.innerHTML = '<i data-feather="alert-triangle" class="mr-2"></i> Generation failed. Please try again.';
|
| 104 |
document.body.appendChild(toast);
|
| 105 |
feather.replace();
|
| 106 |
|
|
|
|
| 108 |
toast.classList.add('opacity-0', 'transition-opacity', 'duration-300');
|
| 109 |
setTimeout(() => toast.remove(), 300);
|
| 110 |
}, 3000);
|
| 111 |
+
}
|
| 112 |
+
});
|
| 113 |
}
|
| 114 |
});
|
style.css
CHANGED
|
@@ -21,6 +21,18 @@ body {
|
|
| 21 |
::-webkit-scrollbar-thumb:hover {
|
| 22 |
background: #dc2626;
|
| 23 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
/* Animation effects */
|
| 26 |
@keyframes float {
|
|
|
|
| 21 |
::-webkit-scrollbar-thumb:hover {
|
| 22 |
background: #dc2626;
|
| 23 |
}
|
| 24 |
+
/* Animation effects and video styles */
|
| 25 |
+
video {
|
| 26 |
+
object-fit: cover;
|
| 27 |
+
width: 100%;
|
| 28 |
+
height: 100%;
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
.progress-bar {
|
| 32 |
+
height: 4px;
|
| 33 |
+
background: #3b82f6;
|
| 34 |
+
transition: width 0.3s;
|
| 35 |
+
}
|
| 36 |
|
| 37 |
/* Animation effects */
|
| 38 |
@keyframes float {
|