File size: 18,002 Bytes
a92c4f7 b141e4b a92c4f7 b141e4b a92c4f7 b141e4b a92c4f7 b141e4b 0d87ed4 b141e4b a92c4f7 b141e4b a92c4f7 b141e4b a92c4f7 b141e4b a92c4f7 b141e4b 18842d4 b141e4b acdd6e6 b141e4b 18842d4 b141e4b 0d87ed4 b141e4b a92c4f7 b141e4b 18842d4 a92c4f7 b141e4b 18842d4 a92c4f7 18842d4 b141e4b a92c4f7 b141e4b a92c4f7 b141e4b a92c4f7 b141e4b a92c4f7 b141e4b a92c4f7 b141e4b a92c4f7 b141e4b 18842d4 0d87ed4 b141e4b a92c4f7 b141e4b 0d87ed4 b141e4b 0d87ed4 b141e4b a92c4f7 b141e4b a92c4f7 b141e4b a92c4f7 b141e4b a92c4f7 b141e4b 18842d4 0d87ed4 b141e4b a92c4f7 b141e4b a92c4f7 b141e4b 18842d4 b141e4b 0d87ed4 b141e4b a92c4f7 b141e4b 0d87ed4 b141e4b 0d87ed4 b141e4b 18842d4 b141e4b a92c4f7 b141e4b a92c4f7 b141e4b a92c4f7 b141e4b a92c4f7 b141e4b a92c4f7 b141e4b 0d87ed4 18842d4 b141e4b 18842d4 0d87ed4 b141e4b a92c4f7 b141e4b 18842d4 b141e4b 18842d4 b141e4b acdd6e6 a92c4f7 b141e4b a92c4f7 b141e4b 18842d4 a92c4f7 b141e4b acdd6e6 b141e4b 0d87ed4 acdd6e6 b141e4b 0d87ed4 b141e4b 0d87ed4 b141e4b acdd6e6 b141e4b 0d87ed4 b141e4b 0d87ed4 b141e4b 0d87ed4 acdd6e6 0d87ed4 b141e4b 18842d4 b141e4b a92c4f7 b141e4b 0d87ed4 b141e4b 0d87ed4 b141e4b 0d87ed4 b141e4b 0d87ed4 b141e4b 18842d4 a92c4f7 b141e4b a92c4f7 18842d4 b141e4b a92c4f7 b141e4b acdd6e6 b141e4b 0d87ed4 b141e4b 0d87ed4 b141e4b acdd6e6 b141e4b acdd6e6 0d87ed4 b141e4b a92c4f7 |
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 |
<!DOCTYPE html>
<html lang="fa" dir="rtl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ساخت ویدیو با هوش مصنوعی - Hugging Face</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
<script src="https://cdn.jsdelivr.net/npm/@huggingface/inference@2.6.4"></script>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body {
background: linear-gradient(135deg, #1a2a6c, #b21f1f, #fdbb2d);
color: #fff;
min-height: 100vh;
padding: 20px;
}
.container {
max-width: 1200px;
margin: 0 auto;
}
header {
text-align: center;
padding: 30px 0;
margin-bottom: 30px;
}
h1 {
font-size: 2.5rem;
margin-bottom: 10px;
text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
}
.subtitle {
font-size: 1.2rem;
opacity: 0.9;
}
.card {
background: rgba(255, 255, 255, 0.1);
backdrop-filter: blur(10px);
border-radius: 15px;
padding: 25px;
margin-bottom: 25px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
border: 1px solid rgba(255, 255, 255, 0.2);
}
.card-title {
display: flex;
align-items: center;
margin-bottom: 20px;
font-size: 1.5rem;
}
.card-title i {
margin-left: 10px;
font-size: 1.8rem;
}
.form-group {
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 8px;
font-weight: 500;
}
input, textarea, select {
width: 100%;
padding: 12px 15px;
border-radius: 8px;
border: 1px solid rgba(255, 255, 255, 0.3);
background: rgba(255, 255, 255, 0.1);
color: #fff;
font-size: 1rem;
transition: all 0.3s ease;
}
input:focus, textarea:focus, select:focus {
outline: none;
border-color: #4dabf7;
box-shadow: 0 0 0 3px rgba(77, 171, 247, 0.3);
}
textarea {
min-height: 120px;
resize: vertical;
}
.btn {
display: inline-flex;
align-items: center;
justify-content: center;
padding: 12px 25px;
background: linear-gradient(45deg, #ff6b6b, #ff8e53);
color: white;
border: none;
border-radius: 8px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}
.btn:hover {
transform: translateY(-2px);
box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
}
.btn i {
margin-right: 8px;
}
.btn-primary {
background: linear-gradient(45deg, #4dabf7, #3bc9db);
}
.btn-success {
background: linear-gradient(45deg, #51cf66, #94d82d);
}
.flex-container {
display: flex;
gap: 25px;
flex-wrap: wrap;
}
.flex-item {
flex: 1;
min-width: 300px;
}
.result-container {
display: none;
text-align: center;
padding: 20px;
}
.video-preview {
width: 100%;
max-width: 600px;
height: 300px;
background: rgba(0, 0, 0, 0.3);
border-radius: 10px;
margin: 20px auto;
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
}
.video-preview video {
max-width: 100%;
max-height: 100%;
border-radius: 8px;
}
.loading {
display: none;
text-align: center;
padding: 20px;
}
.spinner {
width: 50px;
height: 50px;
border: 5px solid rgba(255, 255, 255, 0.3);
border-radius: 50%;
border-top-color: #4dabf7;
animation: spin 1s linear infinite;
margin: 0 auto 15px;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
.file-input-container {
position: relative;
overflow: hidden;
display: inline-block;
width: 100%;
}
.file-input-container input[type=file] {
position: absolute;
left: 0;
top: 0;
opacity: 0;
width: 100%;
height: 100%;
cursor: pointer;
}
.file-input-label {
display: flex;
align-items: center;
justify-content: center;
padding: 12px;
background: rgba(255, 255, 255, 0.1);
border: 2px dashed rgba(255, 255, 255, 0.3);
border-radius: 8px;
cursor: pointer;
transition: all 0.3s ease;
}
.file-input-label:hover {
background: rgba(255, 255, 255, 0.2);
}
.file-input-label i {
margin-left: 8px;
font-size: 1.5rem;
}
.image-preview {
margin-top: 15px;
text-align: center;
}
.image-preview img {
max-width: 100%;
max-height: 200px;
border-radius: 8px;
box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}
.instructions {
margin-top: 30px;
font-size: 0.9rem;
opacity: 0.8;
line-height: 1.6;
}
.error {
background: rgba(255, 0, 0, 0.2);
border: 1px solid rgba(255, 0, 0, 0.5);
border-radius: 8px;
padding: 15px;
margin: 15px 0;
display: none;
}
@media (max-width: 768px) {
.flex-container {
flex-direction: column;
}
h1 {
font-size: 2rem;
}
}
</style>
</head>
<body>
<div class="container">
<header>
<h1>ساخت ویدیو با هوش مصنوعی</h1>
<p class="subtitle">تبدیل متن و تصویر به ویدیو با استفاده از مدل VEO از Hugging Face</p>
</header>
<div class="card">
<div class="card-title">
<i class="fas fa-key"></i>
<h2>تنظیمات احراز هویت</h2>
</div>
<div class="form-group">
<label for="token">توکن Hugging Face</label>
<input type="text" id="token" placeholder="توکن خود را اینجا وارد کنید" required>
<p class="instructions">برای استفاده از این سرویس، نیاز به یک توکن معتبر از Hugging Face دارید. اگر توکن ندارید، از <a href="https://huggingface.co/settings/tokens" target="_blank" style="color: #4dabf7;">این لینک</a> میتوانید ایجاد کنید.</p>
</div>
</div>
<div class="flex-container">
<div class="flex-item">
<div class="card">
<div class="card-title">
<i class="fas fa-font"></i>
<h2>تبدیل متن به ویدیو</h2>
</div>
<div class="form-group">
<label for="text-input">متن خود را وارد کنید</label>
<textarea id="text-input" placeholder="مثلاً: یک مرد جوان در خیابان در حال راه رفتن است"></textarea>
</div>
<button class="btn btn-primary" id="text-to-video-btn">
<i class="fas fa-film"></i>
ساخت ویدیو از متن
</button>
</div>
</div>
<div class="flex-item">
<div class="card">
<div class="card-title">
<i class="fas fa-image"></i>
<h2>تبدیل تصویر به ویدیو</h2>
</div>
<div class="form-group">
<label for="image-input">تصویر خود را انتخاب کنید</label>
<div class="file-input-container">
<div class="file-input-label">
<i class="fas fa-cloud-upload-alt"></i>
<span>انتخاب تصویر</span>
</div>
<input type="file" id="image-input" accept="image/*">
</div>
<div class="image-preview" id="image-preview"></div>
</div>
<div class="form-group">
<label for="image-prompt">توضیح برای ویدیو (اختیاری)</label>
<input type="text" id="image-prompt" placeholder="مثلاً: گربه شروع به رقصیدن میکند">
</div>
<button class="btn btn-success" id="image-to-video-btn">
<i class="fas fa-video"></i>
ساخت ویدیو از تصویر
</button>
</div>
</div>
</div>
<div class="loading" id="loading">
<div class="spinner"></div>
<p>در حال ساخت ویدیو، لطفاً منتظر بمانید...</p>
<p class="instructions">این فرآیند ممکن است چند دقیقه طول بکشد</p>
</div>
<div class="error" id="error-message">
<i class="fas fa-exclamation-triangle"></i>
<span id="error-text">خطایی رخ داده است</span>
</div>
<div class="card result-container" id="result-container">
<div class="card-title">
<i class="fas fa-check-circle"></i>
<h2>ویدیو شما آماده است!</h2>
</div>
<div class="video-preview" id="video-preview">
<video controls id="generated-video">
مرورگر شما از تگ ویدیو پشتیبانی نمیکند.
</video>
</div>
<button class="btn btn-primary" id="download-btn">
<i class="fas fa-download"></i>
دانلود ویدیو
</button>
</div>
</div>
<script>
// عناصر DOM
const tokenInput = document.getElementById('token');
const textInput = document.getElementById('text-input');
const imageInput = document.getElementById('image-input');
const imagePrompt = document.getElementById('image-prompt');
const textToVideoBtn = document.getElementById('text-to-video-btn');
const imageToVideoBtn = document.getElementById('image-to-video-btn');
const loading = document.getElementById('loading');
const resultContainer = document.getElementById('result-container');
const videoPreview = document.getElementById('video-preview');
const generatedVideo = document.getElementById('generated-video');
const downloadBtn = document.getElementById('download-btn');
const imagePreview = document.getElementById('image-preview');
const errorMessage = document.getElementById('error-message');
const errorText = document.getElementById('error-text');
// پیشنمایش تصویر آپلود شده
imageInput.addEventListener('change', function(e) {
const file = e.target.files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(e) {
imagePreview.innerHTML = `<img src="${e.target.result}" alt="تصویر آپلود شده">`;
};
reader.readAsDataURL(file);
}
});
// تبدیل متن به ویدیو
textToVideoBtn.addEventListener('click', async function() {
if (!tokenInput.value) {
showError('لطفاً توکن Hugging Face خود را وارد کنید');
return;
}
if (!textInput.value) {
showError('لطفاً متنی برای تبدیل به ویدیو وارد کنید');
return;
}
hideError();
loading.style.display = 'block';
resultContainer.style.display = 'none';
try {
// استفاده از کتابخانه Hugging Face Inference
const { InferenceClient } = window.HfInference;
const client = new InferenceClient(tokenInput.value);
const videoBlob = await client.textToVideo({
provider: "fal-ai",
model: "akhaliq/veo3.1-fast",
inputs: textInput.value,
});
// نمایش ویدیوی تولید شده
const videoUrl = URL.createObjectURL(videoBlob);
generatedVideo.src = videoUrl;
loading.style.display = 'none';
resultContainer.style.display = 'block';
// تنظیم لینک دانلود
downloadBtn.onclick = function() {
const a = document.createElement('a');
a.href = videoUrl;
a.download = `text-to-video-${Date.now()}.mp4`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
};
} catch (error) {
console.error('خطا در ساخت ویدیو:', error);
showError('خطا در ساخت ویدیو: ' + error.message);
loading.style.display = 'none';
}
});
// تبدیل تصویر به ویدیو
imageToVideoBtn.addEventListener('click', async function() {
if (!tokenInput.value) {
showError('لطفاً توکن Hugging Face خود را وارد کنید');
return;
}
if (!imageInput.files[0]) {
showError('لطفاً تصویری برای تبدیل به ویدیو انتخاب کنید');
return;
}
hideError();
loading.style.display = 'block';
resultContainer.style.display = 'none';
try {
// تبدیل تصویر به Blob
const imageFile = imageInput.files[0];
// استفاده از کتابخانه Hugging Face Inference
const { InferenceClient } = window.HfInference;
const client = new InferenceClient(tokenInput.value);
const videoBlob = await client.imageToVideo({
provider: "fal-ai",
model: "akhaliq/veo3.1-fast-image-to-video",
inputs: imageFile,
parameters: {
prompt: imagePrompt.value || "The image comes to life"
},
});
// نمایش ویدیوی تولید شده
const videoUrl = URL.createObjectURL(videoBlob);
generatedVideo.src = videoUrl;
loading.style.display = 'none';
resultContainer.style.display = 'block';
// تنظیم لینک دانلود
downloadBtn.onclick = function() {
const a = document.createElement('a');
a.href = videoUrl;
a.download = `image-to-video-${Date.now()}.mp4`;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
};
} catch (error) {
console.error('خطا در ساخت ویدیو:', error);
showError('خطا در ساخت ویدیو: ' + error.message);
loading.style.display = 'none';
}
});
// نمایش خطا
function showError(message) {
errorText.textContent = message;
errorMessage.style.display = 'block';
}
// پنهان کردن خطا
function hideError() {
errorMessage.style.display = 'none';
}
</script>
</body>
</html> |