Update index.html
Browse files- index.html +279 -363
index.html
CHANGED
|
@@ -100,14 +100,8 @@
|
|
| 100 |
}
|
| 101 |
textarea { min-height: 120px; resize: vertical; }
|
| 102 |
textarea:focus, input:focus, select:focus { border-color: var(--accent-primary); background: #fff; }
|
| 103 |
-
|
| 104 |
-
input[type="file"] { padding: 10px; font-size: 0.9rem; background: #fff; }
|
| 105 |
|
| 106 |
-
@keyframes move-gradient {
|
| 107 |
-
0% { background-position: 0% 50%; }
|
| 108 |
-
50% { background-position: 100% 50%; }
|
| 109 |
-
100% { background-position: 0% 50%; }
|
| 110 |
-
}
|
| 111 |
.btn-main {
|
| 112 |
width: 100%; padding: 16px;
|
| 113 |
background: linear-gradient(110deg, var(--accent-secondary), var(--accent-primary), var(--accent-secondary));
|
|
@@ -128,10 +122,7 @@
|
|
| 128 |
.btn-main:hover::before { opacity: 1; animation: move-gradient 4s linear infinite; }
|
| 129 |
.btn-main:disabled { opacity: 0.7; cursor: not-allowed; filter: grayscale(1); }
|
| 130 |
|
| 131 |
-
.btn-outline {
|
| 132 |
-
background: transparent; border: 2px solid var(--input-border);
|
| 133 |
-
color: var(--text-secondary); margin-top: 10px; transition: all 0.2s;
|
| 134 |
-
}
|
| 135 |
.btn-outline:hover { border-color: var(--accent-primary); color: var(--accent-primary); }
|
| 136 |
|
| 137 |
.accordion {
|
|
@@ -149,10 +140,16 @@
|
|
| 149 |
margin-bottom: 0; border: 1px solid var(--input-border); border-top: none;
|
| 150 |
}
|
| 151 |
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; padding: 15px 0; }
|
| 152 |
-
.checkbox-wrapper { display: flex; align-items: center; gap: 10px; margin-top: 5px; padding-bottom:
|
| 153 |
-
.checkbox-wrapper:last-child { border-bottom: none; }
|
| 154 |
.settings-group label { font-size: 0.8rem; color: var(--text-secondary); display: block; margin-bottom: 6px; font-weight: 500; }
|
| 155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
.player-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 15px; padding-bottom: 15px; border-bottom: 1px solid var(--panel-border); }
|
| 157 |
|
| 158 |
.download-btn-style {
|
|
@@ -163,23 +160,24 @@
|
|
| 163 |
.download-btn-style.locked { background-color: #f1f5f9; color: #94a3b8; }
|
| 164 |
.download-btn-style.locked:hover { background-color: #e2e8f0; }
|
| 165 |
|
| 166 |
-
audio {
|
| 167 |
-
|
| 168 |
-
|
|
|
|
| 169 |
.lyrics-container {
|
| 170 |
background: var(--input-bg); border-radius: 16px; padding: 20px; max-height: 350px; overflow-y: auto;
|
| 171 |
-
|
| 172 |
-
scroll-behavior: smooth;
|
| 173 |
}
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
.
|
| 180 |
-
color: var(--accent-primary);
|
| 181 |
-
font-weight: 800;
|
| 182 |
}
|
|
|
|
| 183 |
|
| 184 |
#loader { display: none; text-align: center; padding: 20px; }
|
| 185 |
.wave-bars { display: flex; justify-content: center; gap: 4px; height: 30px; align-items: flex-end; }
|
|
@@ -203,10 +201,8 @@
|
|
| 203 |
.h-details span { font-size: 0.8rem; color: var(--text-secondary); }
|
| 204 |
|
| 205 |
.h-delete {
|
| 206 |
-
position: absolute; left: 15px;
|
| 207 |
-
|
| 208 |
-
width: 38px; height: 38px; border-radius: 50%;
|
| 209 |
-
display: flex; align-items: center; justify-content: center;
|
| 210 |
opacity: 0; transform: scale(0.8); transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
|
| 211 |
z-index: 10; box-shadow: 0 4px 10px rgba(229, 62, 62, 0.2);
|
| 212 |
}
|
|
@@ -240,20 +236,13 @@
|
|
| 240 |
|
| 241 |
@keyframes pulse-gold { 0% { box-shadow: 0 0 0 0 rgba(255, 193, 7, 0.7); } 70% { box-shadow: 0 0 0 15px rgba(255, 193, 7, 0); } 100% { box-shadow: 0 0 0 0 rgba(255, 193, 7, 0); } }
|
| 242 |
.upgrade-icon {
|
| 243 |
-
width: 70px; height: 70px;
|
| 244 |
-
background: var(--premium-gradient);
|
| 245 |
border-radius: 50%; color: white; margin: 0 auto 20px;
|
| 246 |
display: flex; align-items: center; justify-content: center;
|
| 247 |
font-size: 2rem; animation: pulse-gold 2s infinite;
|
| 248 |
}
|
| 249 |
-
.btn-upgrade {
|
| 250 |
-
|
| 251 |
-
box-shadow: 0 5px 15px rgba(255, 193, 7, 0.3);
|
| 252 |
-
}
|
| 253 |
-
.btn-upgrade:hover {
|
| 254 |
-
transform: translateY(-2px);
|
| 255 |
-
box-shadow: 0 8px 25px rgba(255, 193, 7, 0.5);
|
| 256 |
-
}
|
| 257 |
|
| 258 |
.modal-overlay.open { display: flex; opacity: 1; }
|
| 259 |
.modal-overlay.open .modal-box { transform: scale(1); }
|
|
@@ -287,22 +276,23 @@
|
|
| 287 |
<div class="settings-group"><label>تعداد گام (Steps):</label><input type="number" id="steps_input" value="20" min="4" max="50"></div>
|
| 288 |
<div class="settings-group"><label>سید (Seed) تصادفی=-1:</label><input type="number" id="seed_input" value="-1"></div>
|
| 289 |
<div class="settings-group"><label>مقیاس هدایت (CFG):</label><input type="number" id="cfg_input" value="7.0" step="0.5"></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
</div>
|
| 291 |
-
|
| 292 |
-
<div class="settings-group" style="margin-bottom: 15px;">
|
| 293 |
-
<label>نمونه صدا (Audio Conditioning):</label>
|
| 294 |
-
<input type="file" id="audioInput" accept="audio/*">
|
| 295 |
-
<div style="font-size: 0.75rem; color: #666; margin-top: 4px;">آپلود یک فایل صوتی برای الهام گرفتن ریتم و ملودی (اختیاری)</div>
|
| 296 |
-
</div>
|
| 297 |
-
|
| 298 |
<div class="checkbox-wrapper">
|
| 299 |
-
<input type="checkbox" id="
|
| 300 |
-
<label for="instrumental_chk" style="font-size: 0.9rem; cursor: pointer;"><b>آهنگ بیکلام (Instrumental)</b><br><span style="font-size: 0.8rem; color: #666;">بدون خواننده، فقط موسیقی</span></label>
|
| 301 |
</div>
|
| 302 |
-
|
| 303 |
-
<div class="checkbox-wrapper">
|
| 304 |
-
<input type="checkbox" id="
|
| 305 |
-
<label for="think_checkbox" style="font-size: 0.9rem; cursor: pointer;"><b>فعالسازی تفکر مدل</b><br><span style="font-size: 0.8rem; color: #666;">افزایش کیفیت آهنگ</span></label>
|
| 306 |
</div>
|
| 307 |
</div>
|
| 308 |
<button id="processBtn" class="btn-main" style="margin-top: 15px;"><div class="btn-main-content">ساخت آهنگ <span>🎵</span></div></button>
|
|
@@ -319,8 +309,10 @@
|
|
| 319 |
<button id="mainDownloadBtn" class="download-btn-style">دانلود آهنگ 📥</button>
|
| 320 |
</div>
|
| 321 |
<div id="playerWrapper"></div>
|
| 322 |
-
<div
|
| 323 |
-
|
|
|
|
|
|
|
| 324 |
<button onclick="location.reload()" class="btn-main btn-outline">برگشت و ساخت آهنگ جدید</button>
|
| 325 |
</div>
|
| 326 |
|
|
@@ -333,14 +325,14 @@
|
|
| 333 |
</div>
|
| 334 |
</div>
|
| 335 |
|
| 336 |
-
<!-- مودال
|
| 337 |
<div class="modal-overlay" id="deleteConfirmModal">
|
| 338 |
<div class="modal-box">
|
| 339 |
<div class="modal-icon-warn">
|
| 340 |
<svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 6h18"></path><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"></path><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"></path></svg>
|
| 341 |
</div>
|
| 342 |
<h3>آیا مطمئن هستید؟</h3>
|
| 343 |
-
<p>این آهنگ برای همیشه از سوابق شما حذف خواهد شد
|
| 344 |
<div class="modal-actions">
|
| 345 |
<button class="btn-modal btn-cancel" onclick="closeDeleteModal()">انصراف</button>
|
| 346 |
<button class="btn-modal btn-confirm" onclick="confirmDelete()">بله، حذف شود</button>
|
|
@@ -348,12 +340,11 @@
|
|
| 348 |
</div>
|
| 349 |
</div>
|
| 350 |
|
| 351 |
-
<!-- مودال ارتقا به نسخه کامل -->
|
| 352 |
<div class="modal-overlay" id="upgradeModal">
|
| 353 |
<div class="modal-box">
|
| 354 |
<div class="upgrade-icon">👑</div>
|
| 355 |
-
<h3 style="font-weight: 800; color: #333;" id="upgradeModalTitle">
|
| 356 |
-
<p style="margin-bottom: 25px; line-height: 1.6;" id="upgradeModalText">برای
|
| 357 |
<div class="modal-actions" style="flex-direction: column;">
|
| 358 |
<button class="btn-modal btn-upgrade" id="btnGoPremium">⭐️ ارتقا به نسخه کامل</button>
|
| 359 |
<button class="btn-modal btn-cancel" onclick="closeUpgradeModal()" style="width: 100%;">فعلاً نه</button>
|
|
@@ -364,12 +355,12 @@
|
|
| 364 |
<script>
|
| 365 |
const ACE_SPACE_URL = "https://ace-step-ace-step-v1-5.hf.space/";
|
| 366 |
const PREMIUM_PAGE_ID = '1149636';
|
| 367 |
-
const PREMIUM_URL = '#/nav/online/news/getSingle/1149636/
|
| 368 |
-
|
| 369 |
let db;
|
| 370 |
let songToDeleteId = null;
|
| 371 |
-
let userSubscriptionStatus = 'free';
|
| 372 |
|
|
|
|
| 373 |
const ideaInput = document.getElementById('ideaInput');
|
| 374 |
const processBtn = document.getElementById('processBtn');
|
| 375 |
const step1 = document.getElementById('step1');
|
|
@@ -386,8 +377,11 @@
|
|
| 386 |
const statusBadge = document.getElementById('statusBadge');
|
| 387 |
const upgradeModalTitle = document.getElementById('upgradeModalTitle');
|
| 388 |
const upgradeModalText = document.getElementById('upgradeModalText');
|
| 389 |
-
const
|
| 390 |
-
const
|
|
|
|
|
|
|
|
|
|
| 391 |
|
| 392 |
const getVal = (id) => document.getElementById(id).value;
|
| 393 |
const getNum = (id) => Number(document.getElementById(id).value);
|
|
@@ -401,7 +395,7 @@
|
|
| 401 |
panel.style.maxHeight = panel.style.maxHeight ? null : panel.scrollHeight + "px";
|
| 402 |
});
|
| 403 |
}
|
| 404 |
-
|
| 405 |
function getFingerprint() {
|
| 406 |
let fp = localStorage.getItem('user_fingerprint');
|
| 407 |
if (!fp) {
|
|
@@ -411,12 +405,8 @@
|
|
| 411 |
return fp;
|
| 412 |
}
|
| 413 |
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
(userObject.accessible_pages.includes(PREMIUM_PAGE_ID) ||
|
| 417 |
-
userObject.accessible_pages.includes(parseInt(PREMIUM_PAGE_ID)));
|
| 418 |
-
}
|
| 419 |
-
|
| 420 |
function updateSubscriptionUI(status) {
|
| 421 |
if (status === 'paid') {
|
| 422 |
statusBadge.textContent = 'نسخه نامحدود';
|
|
@@ -426,192 +416,118 @@
|
|
| 426 |
statusBadge.className = 'status-badge visible badge-free';
|
| 427 |
}
|
| 428 |
}
|
| 429 |
-
|
| 430 |
window.addEventListener('message', (event) => {
|
| 431 |
if (event.data && event.data.type === 'USER_STATUS_RESPONSE') {
|
| 432 |
-
|
| 433 |
-
const userObject = JSON.parse(event.data.payload);
|
| 434 |
-
userSubscriptionStatus = isUserPaid(userObject) ? 'paid' : 'free';
|
| 435 |
-
} catch (e) {
|
| 436 |
-
userSubscriptionStatus = 'free';
|
| 437 |
-
}
|
| 438 |
updateSubscriptionUI(userSubscriptionStatus);
|
| 439 |
}
|
| 440 |
});
|
| 441 |
-
|
| 442 |
parent.postMessage({ type: 'REQUEST_USER_STATUS' }, '*');
|
| 443 |
-
|
|
|
|
| 444 |
function handleSecureDownload(url, e) {
|
| 445 |
if (e) e.preventDefault();
|
| 446 |
if (userSubscriptionStatus === 'free') {
|
| 447 |
upgradeModalTitle.innerText = "دانلود مخصوص اعضای ویژه";
|
| 448 |
-
upgradeModalText.innerText = "برای دانلود آهنگها
|
| 449 |
upgradeModal.classList.add('open');
|
| 450 |
} else {
|
| 451 |
parent.postMessage({ type: 'INITIATE_DOWNLOAD_FROM_URL', payload: { audioUrl: url } }, '*');
|
| 452 |
-
const btn = e ? e.target.closest('button') : null;
|
| 453 |
-
if(btn) {
|
| 454 |
-
const originalText = btn.innerHTML;
|
| 455 |
-
btn.innerHTML = 'در حال ارسال... ⏳';
|
| 456 |
-
setTimeout(() => { btn.innerHTML = originalText; }, 2000);
|
| 457 |
-
}
|
| 458 |
}
|
| 459 |
}
|
| 460 |
-
|
| 461 |
-
document.getElementById('btnGoPremium').addEventListener('click', () => {
|
| 462 |
-
parent.postMessage({ type: 'NAVIGATE_TO_PREMIUM', payload: { url: PREMIUM_URL } }, '*');
|
| 463 |
-
});
|
| 464 |
-
|
| 465 |
function closeUpgradeModal() { upgradeModal.classList.remove('open'); }
|
| 466 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 467 |
function initDB() {
|
| 468 |
const request = indexedDB.open("alphaMusicDB", 1);
|
| 469 |
-
request.onerror = (
|
| 470 |
-
request.onsuccess = (
|
| 471 |
-
request.onupgradeneeded = (
|
| 472 |
}
|
| 473 |
-
|
| 474 |
-
async function saveToHistory(idea, lyrics, audioUrl, lrcData = null) {
|
| 475 |
try {
|
| 476 |
const response = await fetch(audioUrl);
|
| 477 |
const audioBlob = await response.blob();
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
const
|
|
|
|
|
|
|
| 484 |
store.add(newItem);
|
| 485 |
-
|
| 486 |
-
const countReq = store.count();
|
| 487 |
-
countReq.onsuccess = () => {
|
| 488 |
-
if (countReq.result > 10) store.openCursor().onsuccess = (e) => { if(e.target.result) e.target.result.delete(); };
|
| 489 |
-
};
|
| 490 |
-
tx.oncomplete = () => loadHistory();
|
| 491 |
} catch (error) { console.error("Error saving:", error); }
|
| 492 |
}
|
| 493 |
-
|
| 494 |
function loadHistory() {
|
| 495 |
if (!db) return;
|
| 496 |
-
|
| 497 |
-
|
| 498 |
-
|
| 499 |
-
|
| 500 |
-
if (history.length === 0) {
|
| 501 |
-
historyList.innerHTML = '<div style="text-align:center; color:#999; padding:20px;">هنوز آهنگی نساختهاید</div>';
|
| 502 |
-
return;
|
| 503 |
-
}
|
| 504 |
-
history.forEach((item) => {
|
| 505 |
const div = document.createElement('div');
|
| 506 |
div.className = 'history-card';
|
| 507 |
-
div.innerHTML = `
|
| 508 |
-
|
| 509 |
-
<div class="h-icon">🎵</div>
|
| 510 |
-
<div class="h-details">
|
| 511 |
-
<h4>${item.idea.substring(0, 30)}${item.idea.length > 30 ? '...' : ''}</h4>
|
| 512 |
-
<span>${item.date}</span>
|
| 513 |
-
</div>
|
| 514 |
-
</div>
|
| 515 |
-
<div class="h-delete" onclick="askToDelete(event, ${item.id})">
|
| 516 |
-
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 6h18"></path><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"></path><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"></path></svg>
|
| 517 |
-
</div>
|
| 518 |
-
`;
|
| 519 |
-
div.onclick = (e) => {
|
| 520 |
-
if (!e.target.closest('.h-delete')) {
|
| 521 |
-
openHistoryItem(item);
|
| 522 |
-
}
|
| 523 |
-
};
|
| 524 |
historyList.appendChild(div);
|
| 525 |
});
|
| 526 |
};
|
| 527 |
}
|
| 528 |
-
|
| 529 |
-
function askToDelete(event, id) {
|
| 530 |
-
event.stopPropagation();
|
| 531 |
-
songToDeleteId = id;
|
| 532 |
-
deleteModal.classList.add('open');
|
| 533 |
-
}
|
| 534 |
-
|
| 535 |
-
function closeDeleteModal() {
|
| 536 |
-
deleteModal.classList.remove('open');
|
| 537 |
-
songToDeleteId = null;
|
| 538 |
-
}
|
| 539 |
-
|
| 540 |
function confirmDelete() {
|
| 541 |
if (songToDeleteId && db) {
|
| 542 |
-
const
|
| 543 |
-
|
| 544 |
-
|
| 545 |
-
loadHistory();
|
| 546 |
-
closeDeleteModal();
|
| 547 |
-
};
|
| 548 |
}
|
| 549 |
}
|
| 550 |
-
|
| 551 |
-
deleteModal.addEventListener('click', (e) => { if (e.target === deleteModal) closeDeleteModal(); });
|
| 552 |
-
upgradeModal.addEventListener('click', (e) => { if (e.target === upgradeModal) closeUpgradeModal(); });
|
| 553 |
-
|
| 554 |
function openHistoryItem(item) {
|
| 555 |
-
step1.style.display = 'none';
|
| 556 |
-
historySection.style.display = 'none';
|
| 557 |
-
|
| 558 |
const audioURL = URL.createObjectURL(item.audioBlob);
|
| 559 |
-
|
| 560 |
-
headerText.innerHTML = `<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline></svg> آهنگ آرشیو شده`;
|
| 561 |
-
headerText.style.color = 'var(--accent-primary)';
|
| 562 |
-
|
| 563 |
-
mainDownloadBtn.style.display = 'inline-flex';
|
| 564 |
mainDownloadBtn.onclick = (e) => handleSecureDownload(audioURL, e);
|
| 565 |
-
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 570 |
}
|
| 571 |
-
|
| 572 |
initDB();
|
| 573 |
|
| 574 |
-
|
| 575 |
-
|
| 576 |
-
|
| 577 |
-
|
| 578 |
-
|
| 579 |
-
|
| 580 |
-
|
| 581 |
-
|
| 582 |
-
|
| 583 |
-
|
| 584 |
-
|
| 585 |
-
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
const session_hash = Math.random().toString(36).substring(2);
|
| 590 |
-
|
| 591 |
-
const joinResp = await fetch(`${ACE_SPACE_URL}gradio_api/queue/join`, {
|
| 592 |
-
method: 'POST',
|
| 593 |
-
headers: { 'Content-Type': 'application/json' },
|
| 594 |
-
body: JSON.stringify({ data: payloadData, fn_index: fnIndex, session_hash })
|
| 595 |
-
});
|
| 596 |
-
|
| 597 |
-
if (!joinResp.ok) throw new Error(`Gradio Call Failed: ${fnIndex}`);
|
| 598 |
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
}
|
| 608 |
-
};
|
| 609 |
-
|
| 610 |
-
eventSource.onerror = (err) => {
|
| 611 |
-
eventSource.close();
|
| 612 |
-
reject(new Error("Connection error during prediction"));
|
| 613 |
-
};
|
| 614 |
-
});
|
| 615 |
}
|
| 616 |
|
| 617 |
processBtn.addEventListener('click', async () => {
|
|
@@ -622,198 +538,198 @@
|
|
| 622 |
historySection.style.display = 'none';
|
| 623 |
loader.style.display = 'block';
|
| 624 |
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 632 |
}
|
| 633 |
|
| 634 |
-
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
|
|
|
|
|
|
|
| 638 |
loaderText.innerText = "آلفا در حال نوشتن شعر و ملودی...";
|
| 639 |
-
|
| 640 |
-
const response = await fetch('/api/refine', {
|
| 641 |
method: 'POST',
|
| 642 |
headers: {'Content-Type': 'application/json'},
|
| 643 |
body: JSON.stringify({ idea: ideaInput.value, fingerprint: getFingerprint(), is_premium: userSubscriptionStatus === 'paid' })
|
| 644 |
});
|
| 645 |
|
| 646 |
-
if (
|
| 647 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 648 |
if (data.error) throw new Error(data.error);
|
| 649 |
lyrics = data.lyrics;
|
| 650 |
musicPrompt = data.music_prompt;
|
| 651 |
-
} else {
|
| 652 |
-
lyrics = "";
|
| 653 |
}
|
| 654 |
-
|
| 655 |
-
loaderText.innerText = "در حال ضبط آهنگ در استودیو آلفا...";
|
| 656 |
|
| 657 |
-
|
| 658 |
-
|
|
|
|
|
|
|
| 659 |
getNum('steps_input'), getNum('cfg_input'), true, getNum('seed_input'), null, -1,
|
| 660 |
getNum('batch_size'), null, null, 0, -1, "Fill the audio semantic mask based on the given conditions:",
|
| 661 |
-
1,
|
| 662 |
getChk('think_checkbox'), 2, 0, 0.9, "NO USER INPUT", true, true, true, null, false, true, false, false, 0.5, 8, null, [], false, null, null, null, null
|
| 663 |
];
|
| 664 |
|
| 665 |
-
const
|
| 666 |
-
const
|
| 667 |
-
|
| 668 |
-
if(!audioFileObj) throw new Error("Audio generation failed");
|
| 669 |
-
|
| 670 |
-
let lrcData = null;
|
| 671 |
-
if (!isInstrumental) {
|
| 672 |
-
loaderText.innerText = "در حال هماهنگسازی متن و آهنگ...";
|
| 673 |
-
try {
|
| 674 |
-
const lrcOutput = await runGradioFunction(84, [audioFileObj]);
|
| 675 |
-
if (lrcOutput && lrcOutput.data && lrcOutput.data[0] && lrcOutput.data[0].path) {
|
| 676 |
-
const vttFile = lrcOutput.data[0];
|
| 677 |
-
const vttUrl = vttFile.url || `${ACE_SPACE_URL.replace(/\/$/,'')}/gradio_api/file=${vttFile.path}`;
|
| 678 |
-
const resp = await fetch(vttUrl);
|
| 679 |
-
lrcData = await resp.text();
|
| 680 |
-
}
|
| 681 |
-
} catch (e) {
|
| 682 |
-
console.warn("LRC generation failed, using plain lyrics.", e);
|
| 683 |
-
}
|
| 684 |
-
}
|
| 685 |
|
| 686 |
-
|
| 687 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 688 |
|
| 689 |
} catch (e) {
|
| 690 |
-
|
| 691 |
-
|
| 692 |
-
upgradeModalText.innerText = "شما به سقف ۵ آهنگ رایگان در روز رسیدهاید. برای ساخت نامحدود، حساب خود را ارتقا دهید.";
|
| 693 |
-
upgradeModal.classList.add('open');
|
| 694 |
-
} else {
|
| 695 |
-
alert("خطا: " + e.message);
|
| 696 |
-
}
|
| 697 |
-
loader.style.display = 'none';
|
| 698 |
-
step1.style.display = 'block';
|
| 699 |
-
historySection.style.display = 'block';
|
| 700 |
-
processBtn.disabled = false;
|
| 701 |
}
|
| 702 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 703 |
|
| 704 |
-
function findAudioFile(data) {
|
| 705 |
-
let found = null;
|
| 706 |
function traverse(obj) {
|
| 707 |
-
if (
|
| 708 |
-
|
| 709 |
-
|
| 710 |
-
|
| 711 |
-
|
|
|
|
|
|
|
| 712 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 713 |
Object.values(obj).forEach(traverse);
|
| 714 |
}
|
| 715 |
}
|
| 716 |
traverse(data);
|
| 717 |
-
return found;
|
| 718 |
-
}
|
| 719 |
-
|
| 720 |
-
function handleFinalResult(audioUrl, lyrics, idea, lrcData) {
|
| 721 |
-
const fullAudioUrl = audioUrl.startsWith('http') ? audioUrl : ACE_SPACE_URL.replace(/\/$/, '') + audioUrl;
|
| 722 |
-
|
| 723 |
-
const headerText = document.getElementById('resultHeaderText');
|
| 724 |
-
headerText.innerHTML = `<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline></svg>آهنگ جدید آماده شد`;
|
| 725 |
-
headerText.style.color = 'var(--success-color)';
|
| 726 |
-
|
| 727 |
-
finalResult.style.display = 'block';
|
| 728 |
-
mainDownloadBtn.style.display = 'inline-flex';
|
| 729 |
-
mainDownloadBtn.onclick = (e) => handleSecureDownload(fullAudioUrl, e);
|
| 730 |
-
|
| 731 |
-
setupPlayerWithLyrics(fullAudioUrl, lrcData, lyrics);
|
| 732 |
-
saveToHistory(idea, lyrics, fullAudioUrl, lrcData);
|
| 733 |
-
|
| 734 |
-
window.scrollTo({ top: 0, behavior: 'smooth' });
|
| 735 |
-
}
|
| 736 |
-
|
| 737 |
-
// --- توابع پردازش متن و زمانبندی ---
|
| 738 |
-
function formatLyricsHTML(text) {
|
| 739 |
-
return text.replace(/\[(.*?)\]/g, '<span class="lyrics-tag">[$1]</span>');
|
| 740 |
-
}
|
| 741 |
|
| 742 |
-
|
| 743 |
-
|
| 744 |
-
|
| 745 |
-
|
| 746 |
-
|
| 747 |
-
|
| 748 |
-
|
| 749 |
-
|
| 750 |
-
|
| 751 |
-
|
| 752 |
-
|
| 753 |
-
|
| 754 |
-
|
| 755 |
-
|
| 756 |
-
|
|
|
|
| 757 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 758 |
}
|
| 759 |
-
return lines;
|
| 760 |
}
|
| 761 |
-
|
|
|
|
| 762 |
function timeToSeconds(timeStr) {
|
| 763 |
-
const
|
| 764 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 765 |
}
|
| 766 |
|
| 767 |
-
function
|
| 768 |
-
|
| 769 |
finalLyricsBox.innerHTML = '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 770 |
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
p.innerHTML = formatLyricsHTML(line.text.replace(/\n/g, '<br>'));
|
| 785 |
-
finalLyricsBox.appendChild(p);
|
| 786 |
-
});
|
| 787 |
-
|
| 788 |
-
audio.addEventListener('timeupdate', () => {
|
| 789 |
-
const currentTime = audio.currentTime;
|
| 790 |
-
let activeIndex = -1;
|
| 791 |
-
|
| 792 |
-
for (let i = 0; i < parsedLyrics.length; i++) {
|
| 793 |
-
if (currentTime >= parsedLyrics[i].startTime && currentTime < parsedLyrics[i].endTime) {
|
| 794 |
-
activeIndex = i;
|
| 795 |
-
break;
|
| 796 |
-
}
|
| 797 |
-
}
|
| 798 |
-
|
| 799 |
-
document.querySelectorAll('.lyric-line.active').forEach(el => el.classList.remove('active'));
|
| 800 |
-
|
| 801 |
-
if (activeIndex !== -1) {
|
| 802 |
-
const activeEl = document.getElementById(`line-${activeIndex}`);
|
| 803 |
-
if (activeEl) {
|
| 804 |
-
activeEl.classList.add('active');
|
| 805 |
-
activeEl.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
| 806 |
}
|
|
|
|
|
|
|
| 807 |
}
|
| 808 |
-
});
|
| 809 |
-
|
| 810 |
-
} else {
|
| 811 |
-
if (rawLyrics) {
|
| 812 |
-
finalLyricsBox.innerHTML = formatLyricsHTML(rawLyrics);
|
| 813 |
-
} else {
|
| 814 |
-
finalLyricsBox.innerHTML = '<div style="color:#a0aec0; padding-top:100px;">(متن آهنگی موجود نیست)</div>';
|
| 815 |
}
|
| 816 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 817 |
}
|
| 818 |
|
| 819 |
const canvas = document.getElementById('music-canvas');
|
|
|
|
| 100 |
}
|
| 101 |
textarea { min-height: 120px; resize: vertical; }
|
| 102 |
textarea:focus, input:focus, select:focus { border-color: var(--accent-primary); background: #fff; }
|
|
|
|
|
|
|
| 103 |
|
| 104 |
+
@keyframes move-gradient { 0% { background-position: 0% 50%; } 50% { background-position: 100% 50%; } 100% { background-position: 0% 50%; } }
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
.btn-main {
|
| 106 |
width: 100%; padding: 16px;
|
| 107 |
background: linear-gradient(110deg, var(--accent-secondary), var(--accent-primary), var(--accent-secondary));
|
|
|
|
| 122 |
.btn-main:hover::before { opacity: 1; animation: move-gradient 4s linear infinite; }
|
| 123 |
.btn-main:disabled { opacity: 0.7; cursor: not-allowed; filter: grayscale(1); }
|
| 124 |
|
| 125 |
+
.btn-outline { background: transparent; border: 2px solid var(--input-border); color: var(--text-secondary); margin-top: 10px; transition: all 0.2s; }
|
|
|
|
|
|
|
|
|
|
| 126 |
.btn-outline:hover { border-color: var(--accent-primary); color: var(--accent-primary); }
|
| 127 |
|
| 128 |
.accordion {
|
|
|
|
| 140 |
margin-bottom: 0; border: 1px solid var(--input-border); border-top: none;
|
| 141 |
}
|
| 142 |
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; padding: 15px 0; }
|
| 143 |
+
.checkbox-wrapper { display: flex; align-items: center; gap: 10px; margin-top: 5px; padding-bottom: 15px; border-top: 1px solid #e2e8f0; padding-top: 15px; }
|
|
|
|
| 144 |
.settings-group label { font-size: 0.8rem; color: var(--text-secondary); display: block; margin-bottom: 6px; font-weight: 500; }
|
| 145 |
|
| 146 |
+
/* استایل آپلود فایل */
|
| 147 |
+
.file-input-wrapper { display: flex; align-items: center; gap: 10px; width: 100%; }
|
| 148 |
+
.btn-file-upload { background: #fff; border: 1px solid var(--input-border); border-radius: 10px; padding: 10px 15px; font-size: 0.9rem; cursor: pointer; transition: 0.2s; flex-shrink: 0; }
|
| 149 |
+
.btn-file-upload:hover { background: #f0f4ff; border-color: var(--accent-primary); color: var(--accent-primary); }
|
| 150 |
+
#file-name-display { flex-grow: 1; text-align: right; font-size: 0.85rem; color: #666; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
| 151 |
+
#clear-file-btn { background: #fee2e2; color: var(--danger-color); border: none; width: 28px; height: 28px; border-radius: 50%; cursor: pointer; font-weight: bold; flex-shrink: 0; }
|
| 152 |
+
|
| 153 |
.player-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 15px; padding-bottom: 15px; border-bottom: 1px solid var(--panel-border); }
|
| 154 |
|
| 155 |
.download-btn-style {
|
|
|
|
| 160 |
.download-btn-style.locked { background-color: #f1f5f9; color: #94a3b8; }
|
| 161 |
.download-btn-style.locked:hover { background-color: #e2e8f0; }
|
| 162 |
|
| 163 |
+
.audio-item { margin-bottom: 10px; }
|
| 164 |
+
audio { width: 100%; height: 45px; border-radius: 20px; margin-top: 5px; }
|
| 165 |
+
|
| 166 |
+
/* استایل متن آهنگ کارائوکه */
|
| 167 |
.lyrics-container {
|
| 168 |
background: var(--input-bg); border-radius: 16px; padding: 20px; max-height: 350px; overflow-y: auto;
|
| 169 |
+
text-align: center; border: 1px solid var(--input-border); margin-top: 15px;
|
|
|
|
| 170 |
}
|
| 171 |
+
.lyrics-line {
|
| 172 |
+
font-size: 1.1rem; line-height: 1.8; color: #626F86;
|
| 173 |
+
transition: all 0.3s ease; padding: 8px 12px; border-radius: 10px;
|
| 174 |
+
opacity: 0.6; cursor: default;
|
| 175 |
+
}
|
| 176 |
+
.lyrics-line.active {
|
| 177 |
+
background-color: var(--accent-glow); color: var(--accent-primary);
|
| 178 |
+
transform: scale(1.05); font-weight: 800; opacity: 1;
|
| 179 |
}
|
| 180 |
+
.lyrics-tag { color: var(--accent-secondary); font-weight: 700; display: block; margin-top: 15px; font-size: 0.8em; }
|
| 181 |
|
| 182 |
#loader { display: none; text-align: center; padding: 20px; }
|
| 183 |
.wave-bars { display: flex; justify-content: center; gap: 4px; height: 30px; align-items: flex-end; }
|
|
|
|
| 201 |
.h-details span { font-size: 0.8rem; color: var(--text-secondary); }
|
| 202 |
|
| 203 |
.h-delete {
|
| 204 |
+
position: absolute; left: 15px; background: #fee2e2; color: var(--danger-color);
|
| 205 |
+
width: 38px; height: 38px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
|
|
|
|
|
|
|
| 206 |
opacity: 0; transform: scale(0.8); transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
|
| 207 |
z-index: 10; box-shadow: 0 4px 10px rgba(229, 62, 62, 0.2);
|
| 208 |
}
|
|
|
|
| 236 |
|
| 237 |
@keyframes pulse-gold { 0% { box-shadow: 0 0 0 0 rgba(255, 193, 7, 0.7); } 70% { box-shadow: 0 0 0 15px rgba(255, 193, 7, 0); } 100% { box-shadow: 0 0 0 0 rgba(255, 193, 7, 0); } }
|
| 238 |
.upgrade-icon {
|
| 239 |
+
width: 70px; height: 70px; background: var(--premium-gradient);
|
|
|
|
| 240 |
border-radius: 50%; color: white; margin: 0 auto 20px;
|
| 241 |
display: flex; align-items: center; justify-content: center;
|
| 242 |
font-size: 2rem; animation: pulse-gold 2s infinite;
|
| 243 |
}
|
| 244 |
+
.btn-upgrade { background: var(--premium-gradient); color: #333; box-shadow: 0 5px 15px rgba(255, 193, 7, 0.3); }
|
| 245 |
+
.btn-upgrade:hover { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(255, 193, 7, 0.5); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
|
| 247 |
.modal-overlay.open { display: flex; opacity: 1; }
|
| 248 |
.modal-overlay.open .modal-box { transform: scale(1); }
|
|
|
|
| 276 |
<div class="settings-group"><label>تعداد گام (Steps):</label><input type="number" id="steps_input" value="20" min="4" max="50"></div>
|
| 277 |
<div class="settings-group"><label>سید (Seed) تصادفی=-1:</label><input type="number" id="seed_input" value="-1"></div>
|
| 278 |
<div class="settings-group"><label>مقیاس هدایت (CFG):</label><input type="number" id="cfg_input" value="7.0" step="0.5"></div>
|
| 279 |
+
<!-- المان جدید آپلود فایل -->
|
| 280 |
+
<div class="settings-group" style="grid-column: 1 / -1;">
|
| 281 |
+
<label>آهنگ نمونه (برای الهام گرفتن مدل):</label>
|
| 282 |
+
<div class="file-input-wrapper">
|
| 283 |
+
<input type="file" id="audio_condition_input" accept="audio/*" style="display:none;">
|
| 284 |
+
<button type="button" class="btn-file-upload" onclick="document.getElementById('audio_condition_input').click();">انتخاب فایل صوتی</button>
|
| 285 |
+
<span id="file-name-display">فایلی انتخاب نشده</span>
|
| 286 |
+
<button id="clear-file-btn" style="display:none;">×</button>
|
| 287 |
+
</div>
|
| 288 |
+
</div>
|
| 289 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 290 |
<div class="checkbox-wrapper">
|
| 291 |
+
<input type="checkbox" id="think_checkbox" checked><label for="think_checkbox" style="font-size: 0.9rem; cursor: pointer;"><b>فعالسازی تفکر مدل</b><br><span style="font-size: 0.8rem; color: #666;">افزایش کیفیت آهنگ</span></label>
|
|
|
|
| 292 |
</div>
|
| 293 |
+
<!-- چکباکس جدید بیکلام -->
|
| 294 |
+
<div class="checkbox-wrapper" style="border-top: none; padding-top: 0;">
|
| 295 |
+
<input type="checkbox" id="instrumental_checkbox"><label for="instrumental_checkbox" style="font-size: 0.9rem; cursor: pointer;"><b>ساخت آهنگ بیکلام (Instrumental)</b><br><span style="font-size: 0.8rem; color: #666;">شعر ساخته نخواهد شد</span></label>
|
|
|
|
| 296 |
</div>
|
| 297 |
</div>
|
| 298 |
<button id="processBtn" class="btn-main" style="margin-top: 15px;"><div class="btn-main-content">ساخت آهنگ <span>🎵</span></div></button>
|
|
|
|
| 309 |
<button id="mainDownloadBtn" class="download-btn-style">دانلود آهنگ 📥</button>
|
| 310 |
</div>
|
| 311 |
<div id="playerWrapper"></div>
|
| 312 |
+
<div id="lyricsSection" style="display: block;">
|
| 313 |
+
<div class="form-label" style="margin-top: 20px; justify-content: center; color: #718096;">متن آهنگ</div>
|
| 314 |
+
<div class="lyrics-container" id="finalLyricsBox"></div>
|
| 315 |
+
</div>
|
| 316 |
<button onclick="location.reload()" class="btn-main btn-outline">برگشت و ساخت آهنگ جدید</button>
|
| 317 |
</div>
|
| 318 |
|
|
|
|
| 325 |
</div>
|
| 326 |
</div>
|
| 327 |
|
| 328 |
+
<!-- مودالها -->
|
| 329 |
<div class="modal-overlay" id="deleteConfirmModal">
|
| 330 |
<div class="modal-box">
|
| 331 |
<div class="modal-icon-warn">
|
| 332 |
<svg width="30" height="30" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 6h18"></path><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"></path><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"></path></svg>
|
| 333 |
</div>
|
| 334 |
<h3>آیا مطمئن هستید؟</h3>
|
| 335 |
+
<p>این آهنگ برای همیشه از سوابق شما حذف خواهد شد.</p>
|
| 336 |
<div class="modal-actions">
|
| 337 |
<button class="btn-modal btn-cancel" onclick="closeDeleteModal()">انصراف</button>
|
| 338 |
<button class="btn-modal btn-confirm" onclick="confirmDelete()">بله، حذف شود</button>
|
|
|
|
| 340 |
</div>
|
| 341 |
</div>
|
| 342 |
|
|
|
|
| 343 |
<div class="modal-overlay" id="upgradeModal">
|
| 344 |
<div class="modal-box">
|
| 345 |
<div class="upgrade-icon">👑</div>
|
| 346 |
+
<h3 style="font-weight: 800; color: #333;" id="upgradeModalTitle">ارتقا به نسخه کامل</h3>
|
| 347 |
+
<p style="margin-bottom: 25px; line-height: 1.6;" id="upgradeModalText">برای استفاده نامحدود و دانلود با کیفیت اصلی، حساب خود را ارتقا دهید.</p>
|
| 348 |
<div class="modal-actions" style="flex-direction: column;">
|
| 349 |
<button class="btn-modal btn-upgrade" id="btnGoPremium">⭐️ ارتقا به نسخه کامل</button>
|
| 350 |
<button class="btn-modal btn-cancel" onclick="closeUpgradeModal()" style="width: 100%;">فعلاً نه</button>
|
|
|
|
| 355 |
<script>
|
| 356 |
const ACE_SPACE_URL = "https://ace-step-ace-step-v1-5.hf.space/";
|
| 357 |
const PREMIUM_PAGE_ID = '1149636';
|
| 358 |
+
const PREMIUM_URL = '#/nav/online/news/getSingle/1149636/...'; //
|
|
|
|
| 359 |
let db;
|
| 360 |
let songToDeleteId = null;
|
| 361 |
+
let userSubscriptionStatus = 'free';
|
| 362 |
|
| 363 |
+
// المانها
|
| 364 |
const ideaInput = document.getElementById('ideaInput');
|
| 365 |
const processBtn = document.getElementById('processBtn');
|
| 366 |
const step1 = document.getElementById('step1');
|
|
|
|
| 377 |
const statusBadge = document.getElementById('statusBadge');
|
| 378 |
const upgradeModalTitle = document.getElementById('upgradeModalTitle');
|
| 379 |
const upgradeModalText = document.getElementById('upgradeModalText');
|
| 380 |
+
const audioConditionInput = document.getElementById('audio_condition_input');
|
| 381 |
+
const fileNameDisplay = document.getElementById('file-name-display');
|
| 382 |
+
const clearFileBtn = document.getElementById('clear-file-btn');
|
| 383 |
+
const instrumentalCheckbox = document.getElementById('instrumental_checkbox');
|
| 384 |
+
const lyricsSection = document.getElementById('lyricsSection');
|
| 385 |
|
| 386 |
const getVal = (id) => document.getElementById(id).value;
|
| 387 |
const getNum = (id) => Number(document.getElementById(id).value);
|
|
|
|
| 395 |
panel.style.maxHeight = panel.style.maxHeight ? null : panel.scrollHeight + "px";
|
| 396 |
});
|
| 397 |
}
|
| 398 |
+
|
| 399 |
function getFingerprint() {
|
| 400 |
let fp = localStorage.getItem('user_fingerprint');
|
| 401 |
if (!fp) {
|
|
|
|
| 405 |
return fp;
|
| 406 |
}
|
| 407 |
|
| 408 |
+
// --- مدیریت اشتراک ---
|
| 409 |
+
function isUserPaid(userObject) { return userObject && userObject.isLogin && userObject.accessible_pages && (userObject.accessible_pages.includes(PREMIUM_PAGE_ID) || userObject.accessible_pages.includes(parseInt(PREMIUM_PAGE_ID))); }
|
|
|
|
|
|
|
|
|
|
|
|
|
| 410 |
function updateSubscriptionUI(status) {
|
| 411 |
if (status === 'paid') {
|
| 412 |
statusBadge.textContent = 'نسخه نامحدود';
|
|
|
|
| 416 |
statusBadge.className = 'status-badge visible badge-free';
|
| 417 |
}
|
| 418 |
}
|
|
|
|
| 419 |
window.addEventListener('message', (event) => {
|
| 420 |
if (event.data && event.data.type === 'USER_STATUS_RESPONSE') {
|
| 421 |
+
userSubscriptionStatus = isUserPaid(JSON.parse(event.data.payload)) ? 'paid' : 'free';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 422 |
updateSubscriptionUI(userSubscriptionStatus);
|
| 423 |
}
|
| 424 |
});
|
|
|
|
| 425 |
parent.postMessage({ type: 'REQUEST_USER_STATUS' }, '*');
|
| 426 |
+
|
| 427 |
+
// --- مدیریت مودالها و دانلود ---
|
| 428 |
function handleSecureDownload(url, e) {
|
| 429 |
if (e) e.preventDefault();
|
| 430 |
if (userSubscriptionStatus === 'free') {
|
| 431 |
upgradeModalTitle.innerText = "دانلود مخصوص اعضای ویژه";
|
| 432 |
+
upgradeModalText.innerText = "برای دانلود آهنگها با کیفیت اصلی، لطفا حساب خود را به نسخه نامحدود ارتقا دهید.";
|
| 433 |
upgradeModal.classList.add('open');
|
| 434 |
} else {
|
| 435 |
parent.postMessage({ type: 'INITIATE_DOWNLOAD_FROM_URL', payload: { audioUrl: url } }, '*');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 436 |
}
|
| 437 |
}
|
| 438 |
+
document.getElementById('btnGoPremium').addEventListener('click', () => { parent.postMessage({ type: 'NAVIGATE_TO_PREMIUM', payload: { url: PREMIUM_URL } }, '*'); });
|
|
|
|
|
|
|
|
|
|
|
|
|
| 439 |
function closeUpgradeModal() { upgradeModal.classList.remove('open'); }
|
| 440 |
+
function closeDeleteModal() { deleteModal.classList.remove('open'); songToDeleteId = null; }
|
| 441 |
+
deleteModal.addEventListener('click', (e) => { if (e.target === deleteModal) closeDeleteModal(); });
|
| 442 |
+
upgradeModal.addEventListener('click', (e) => { if (e.target === upgradeModal) closeUpgradeModal(); });
|
| 443 |
+
|
| 444 |
+
// --- مدیریت دیتابیس IndexedDB ---
|
| 445 |
function initDB() {
|
| 446 |
const request = indexedDB.open("alphaMusicDB", 1);
|
| 447 |
+
request.onerror = (e) => console.error("DB error:", e);
|
| 448 |
+
request.onsuccess = (e) => { db = e.target.result; loadHistory(); };
|
| 449 |
+
request.onupgradeneeded = (e) => { e.target.result.createObjectStore("songs", { keyPath: "id" }); };
|
| 450 |
}
|
| 451 |
+
async function saveToHistory(idea, lyrics, audioUrl, vttUrl) {
|
|
|
|
| 452 |
try {
|
| 453 |
const response = await fetch(audioUrl);
|
| 454 |
const audioBlob = await response.blob();
|
| 455 |
+
let vttContent = "";
|
| 456 |
+
if (vttUrl) {
|
| 457 |
+
const vttResponse = await fetch(vttUrl);
|
| 458 |
+
vttContent = await vttResponse.text();
|
| 459 |
+
}
|
| 460 |
+
const newItem = { id: Date.now(), idea, lyrics, audioBlob, vttContent, date: new Date().toLocaleDateString('fa-IR', { hour: '2-digit', minute: '2-digit' }) };
|
| 461 |
+
const transaction = db.transaction(["songs"], "readwrite");
|
| 462 |
+
const store = transaction.objectStore("songs");
|
| 463 |
store.add(newItem);
|
| 464 |
+
transaction.oncomplete = () => loadHistory();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 465 |
} catch (error) { console.error("Error saving:", error); }
|
| 466 |
}
|
|
|
|
| 467 |
function loadHistory() {
|
| 468 |
if (!db) return;
|
| 469 |
+
db.transaction(["songs"],"readonly").objectStore("songs").getAll().onsuccess = (e) => {
|
| 470 |
+
const history = e.target.result.sort((a,b) => b.id - a.id);
|
| 471 |
+
historyList.innerHTML = history.length === 0 ? '<div style="text-align:center; color:#999; padding:20px;">هنوز آهنگی نساختهاید</div>' : '';
|
| 472 |
+
history.forEach(item => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 473 |
const div = document.createElement('div');
|
| 474 |
div.className = 'history-card';
|
| 475 |
+
div.innerHTML = `<div class="h-info"><div class="h-icon">🎵</div><div class="h-details"><h4>${item.idea.substring(0, 30)}${item.idea.length > 30 ? '...' : ''}</h4><span>${item.date}</span></div></div><div class="h-delete" onclick="askToDelete(event, ${item.id})"><svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 6h18"></path><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"></path><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"></path></svg></div>`;
|
| 476 |
+
div.onclick = (ev) => { if (!ev.target.closest('.h-delete')) openHistoryItem(item); };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 477 |
historyList.appendChild(div);
|
| 478 |
});
|
| 479 |
};
|
| 480 |
}
|
| 481 |
+
function askToDelete(event, id) { event.stopPropagation(); songToDeleteId = id; deleteModal.classList.add('open'); }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 482 |
function confirmDelete() {
|
| 483 |
if (songToDeleteId && db) {
|
| 484 |
+
const transaction = db.transaction(["songs"], "readwrite");
|
| 485 |
+
transaction.objectStore("songs").delete(songToDeleteId);
|
| 486 |
+
transaction.oncomplete = () => { loadHistory(); closeDeleteModal(); };
|
|
|
|
|
|
|
|
|
|
| 487 |
}
|
| 488 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 489 |
function openHistoryItem(item) {
|
| 490 |
+
step1.style.display = 'none'; historySection.style.display = 'none';
|
|
|
|
|
|
|
| 491 |
const audioURL = URL.createObjectURL(item.audioBlob);
|
| 492 |
+
document.getElementById('resultHeaderText').innerHTML = `<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline></svg> آهنگ آرشیو شده`;
|
|
|
|
|
|
|
|
|
|
|
|
|
| 493 |
mainDownloadBtn.onclick = (e) => handleSecureDownload(audioURL, e);
|
| 494 |
+
const audioEl = document.createElement('audio');
|
| 495 |
+
audioEl.controls = true; audioEl.autoplay = true; audioEl.src = audioURL;
|
| 496 |
+
playerWrapper.innerHTML = ''; playerWrapper.appendChild(audioEl);
|
| 497 |
+
if (item.vttContent) {
|
| 498 |
+
lyricsSection.style.display = 'block';
|
| 499 |
+
displayKaraokeLyrics(item.vttContent, audioEl);
|
| 500 |
+
} else {
|
| 501 |
+
lyricsSection.style.display = 'none';
|
| 502 |
+
}
|
| 503 |
+
finalResult.style.display = 'block'; window.scrollTo({ top: 0, behavior: 'smooth' });
|
| 504 |
}
|
|
|
|
| 505 |
initDB();
|
| 506 |
|
| 507 |
+
// --- مدیریت آپلود و حالت بیکلام ---
|
| 508 |
+
audioConditionInput.addEventListener('change', () => {
|
| 509 |
+
if (audioConditionInput.files.length > 0) {
|
| 510 |
+
fileNameDisplay.textContent = audioConditionInput.files[0].name;
|
| 511 |
+
clearFileBtn.style.display = 'inline-block';
|
| 512 |
+
}
|
| 513 |
+
});
|
| 514 |
+
clearFileBtn.addEventListener('click', () => {
|
| 515 |
+
audioConditionInput.value = '';
|
| 516 |
+
fileNameDisplay.textContent = 'فایلی انتخاب نشده';
|
| 517 |
+
clearFileBtn.style.display = 'none';
|
| 518 |
+
});
|
| 519 |
+
instrumentalCheckbox.addEventListener('change', (e) => {
|
| 520 |
+
ideaInput.placeholder = e.target.checked ? 'توضیحات آهنگ بیکلام (مثال: آرامشبخش، پیانو و ویولن)' : 'مثال: آهنگ تولد برای سمیرا، سبک پاپ شاد...';
|
| 521 |
+
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 522 |
|
| 523 |
+
// --- فرآیند اصلی ---
|
| 524 |
+
async function uploadFile(file) {
|
| 525 |
+
const formData = new FormData();
|
| 526 |
+
formData.append("files", file);
|
| 527 |
+
const response = await fetch(`${ACE_SPACE_URL}gradio_api/upload`, { method: 'POST', body: formData });
|
| 528 |
+
if (!response.ok) throw new Error('خطا در آپلود فایل نمونه');
|
| 529 |
+
const result = await response.json();
|
| 530 |
+
return result[0]; // [ "/tmp/gradio/.../file.wav" ]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 531 |
}
|
| 532 |
|
| 533 |
processBtn.addEventListener('click', async () => {
|
|
|
|
| 538 |
historySection.style.display = 'none';
|
| 539 |
loader.style.display = 'block';
|
| 540 |
|
| 541 |
+
let audioConditionObj = null;
|
| 542 |
+
let lyrics = "";
|
| 543 |
+
let musicPrompt = "";
|
| 544 |
|
| 545 |
+
try {
|
| 546 |
+
// مرحله ۱: آپلود فایل نمونه (در صورت وجود)
|
| 547 |
+
if (audioConditionInput.files.length > 0) {
|
| 548 |
+
loaderText.innerText = "در حال آپلود آهنگ نمونه...";
|
| 549 |
+
const file = audioConditionInput.files[0];
|
| 550 |
+
const serverPath = await uploadFile(file);
|
| 551 |
+
audioConditionObj = {
|
| 552 |
+
path: serverPath,
|
| 553 |
+
url: ACE_SPACE_URL + 'gradio_api/file=' + serverPath,
|
| 554 |
+
orig_name: file.name,
|
| 555 |
+
size: file.size,
|
| 556 |
+
mime_type: file.type,
|
| 557 |
+
meta: { _type: "gradio.FileData" }
|
| 558 |
+
};
|
| 559 |
}
|
| 560 |
|
| 561 |
+
// مرحله ۲: آمادهسازی متن و شعر
|
| 562 |
+
const isInstrumental = instrumentalCheckbox.checked;
|
| 563 |
+
if (isInstrumental) {
|
| 564 |
+
lyrics = ""; // برای بیکلام، شعر خالی است
|
| 565 |
+
musicPrompt = ideaInput.value + " ,instrumental"; // اضافه کردن کلمه بیکلام به پرامپت
|
| 566 |
+
} else {
|
| 567 |
loaderText.innerText = "آلفا در حال نوشتن شعر و ملودی...";
|
| 568 |
+
const refineResponse = await fetch('/api/refine', {
|
|
|
|
| 569 |
method: 'POST',
|
| 570 |
headers: {'Content-Type': 'application/json'},
|
| 571 |
body: JSON.stringify({ idea: ideaInput.value, fingerprint: getFingerprint(), is_premium: userSubscriptionStatus === 'paid' })
|
| 572 |
});
|
| 573 |
|
| 574 |
+
if (refineResponse.status === 429) { // مدیریت محدودیت
|
| 575 |
+
loader.style.display = 'none'; step1.style.display = 'block'; historySection.style.display = 'block'; processBtn.disabled = false;
|
| 576 |
+
upgradeModalTitle.innerText = "محدودیت ساخت روزانه"; upgradeModalText.innerText = "شما به سقف ۵ آهنگ رایگان در روز رسیدهاید. برای ساخت نامحدود، حساب خود را ارتقا دهید.";
|
| 577 |
+
upgradeModal.classList.add('open');
|
| 578 |
+
return;
|
| 579 |
+
}
|
| 580 |
+
const data = await refineResponse.json();
|
| 581 |
if (data.error) throw new Error(data.error);
|
| 582 |
lyrics = data.lyrics;
|
| 583 |
musicPrompt = data.music_prompt;
|
|
|
|
|
|
|
| 584 |
}
|
|
|
|
|
|
|
| 585 |
|
| 586 |
+
// مرحله ۳: ارسال درخواست اصلی ساخت آهنگ
|
| 587 |
+
loaderText.innerText = "در حال ضبط آهنگ در استودیو آلفا...";
|
| 588 |
+
const payload = [
|
| 589 |
+
getVal('model_select'), "custom", audioConditionObj, "unknown", musicPrompt, lyrics, 0, "", "", "unknown",
|
| 590 |
getNum('steps_input'), getNum('cfg_input'), true, getNum('seed_input'), null, -1,
|
| 591 |
getNum('batch_size'), null, null, 0, -1, "Fill the audio semantic mask based on the given conditions:",
|
| 592 |
+
1, "text2music", false, 0, 1, 3, "ode", "", "mp3", 0.85,
|
| 593 |
getChk('think_checkbox'), 2, 0, 0.9, "NO USER INPUT", true, true, true, null, false, true, false, false, 0.5, 8, null, [], false, null, null, null, null
|
| 594 |
];
|
| 595 |
|
| 596 |
+
const session_hash = Math.random().toString(36).substring(2);
|
| 597 |
+
const joinResp = await fetch(`${ACE_SPACE_URL}gradio_api/queue/join`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ data: payload, fn_index: 77, session_hash }) });
|
| 598 |
+
if (!joinResp.ok) throw new Error('خطا در اتصال به سرور موزیک');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 599 |
|
| 600 |
+
const eventSource = new EventSource(`${ACE_SPACE_URL}gradio_api/queue/data?session_hash=${session_hash}`);
|
| 601 |
+
eventSource.onmessage = (event) => {
|
| 602 |
+
const msg = JSON.parse(event.data);
|
| 603 |
+
if (msg.msg === 'process_starts') loaderText.innerText = "هوش مصنوعی در حال خواندن...";
|
| 604 |
+
else if (msg.msg === 'process_completed') {
|
| 605 |
+
eventSource.close();
|
| 606 |
+
loader.style.display = 'none';
|
| 607 |
+
handleAudioOutput(msg.output, lyrics, ideaInput.value);
|
| 608 |
+
}
|
| 609 |
+
};
|
| 610 |
+
eventSource.onerror = () => { throw new Error('ارتباط با سرور قطع شد.'); };
|
| 611 |
|
| 612 |
} catch (e) {
|
| 613 |
+
alert("خطا: " + e.message);
|
| 614 |
+
loader.style.display = 'none'; step1.style.display = 'block'; historySection.style.display = 'block'; processBtn.disabled = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 615 |
}
|
| 616 |
});
|
| 617 |
+
|
| 618 |
+
async function handleAudioOutput(data, lyrics, idea) {
|
| 619 |
+
let hasResult = false;
|
| 620 |
+
let audioUrl = null;
|
| 621 |
+
let vttUrl = null;
|
| 622 |
|
|
|
|
|
|
|
| 623 |
function traverse(obj) {
|
| 624 |
+
if (typeof obj === 'string') {
|
| 625 |
+
if (obj.includes('/file=') && obj.endsWith('.mp3')) {
|
| 626 |
+
hasResult = true;
|
| 627 |
+
audioUrl = obj.startsWith('http') ? obj : ACE_SPACE_URL.replace(/\/$/, '') + obj;
|
| 628 |
+
}
|
| 629 |
+
if (obj.includes('/file=') && obj.endsWith('.vtt')) {
|
| 630 |
+
vttUrl = obj.startsWith('http') ? obj : ACE_SPACE_URL.replace(/\/$/, '') + obj;
|
| 631 |
}
|
| 632 |
+
} else if (obj && typeof obj === 'object') {
|
| 633 |
+
if (obj.url && obj.url.endsWith('.mp3')) {
|
| 634 |
+
hasResult = true; audioUrl = obj.url;
|
| 635 |
+
}
|
| 636 |
+
if (obj.url && obj.url.endsWith('.vtt')) { vttUrl = obj.url; }
|
| 637 |
Object.values(obj).forEach(traverse);
|
| 638 |
}
|
| 639 |
}
|
| 640 |
traverse(data);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 641 |
|
| 642 |
+
if (hasResult) {
|
| 643 |
+
document.getElementById('resultHeaderText').innerHTML = `<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"></path><polyline points="22 4 12 14.01 9 11.01"></polyline></svg>آهنگ جدید آماده شد`;
|
| 644 |
+
mainDownloadBtn.onclick = (e) => handleSecureDownload(audioUrl, e);
|
| 645 |
+
saveToHistory(idea, lyrics, audioUrl, vttUrl);
|
| 646 |
+
|
| 647 |
+
const audioEl = document.createElement('audio');
|
| 648 |
+
audioEl.controls = true; audioEl.autoplay = true; audioEl.src = audioUrl;
|
| 649 |
+
playerWrapper.innerHTML = ''; playerWrapper.appendChild(audioEl);
|
| 650 |
+
|
| 651 |
+
if (vttUrl) {
|
| 652 |
+
lyricsSection.style.display = 'block';
|
| 653 |
+
const vttResponse = await fetch(vttUrl);
|
| 654 |
+
const vttContent = await vttResponse.text();
|
| 655 |
+
displayKaraokeLyrics(vttContent, audioEl);
|
| 656 |
+
} else {
|
| 657 |
+
lyricsSection.style.display = 'none';
|
| 658 |
}
|
| 659 |
+
|
| 660 |
+
finalResult.style.display = 'block';
|
| 661 |
+
window.scrollTo({ top: 0, behavior: 'smooth' });
|
| 662 |
+
} else {
|
| 663 |
+
alert("فایل صوتی یافت نشد!");
|
| 664 |
+
step1.style.display = 'block'; historySection.style.display = 'block';
|
| 665 |
}
|
|
|
|
| 666 |
}
|
| 667 |
+
|
| 668 |
+
// --- توابع کارائوکه ---
|
| 669 |
function timeToSeconds(timeStr) {
|
| 670 |
+
const parts = timeStr.split(':');
|
| 671 |
+
const secondsAndMs = parts[2].split('.');
|
| 672 |
+
return parseInt(parts[0], 10) * 3600 + parseInt(parts[1], 10) * 60 + parseInt(secondsAndMs[0], 10) + parseInt(secondsAndMs[1], 10) / 1000;
|
| 673 |
+
}
|
| 674 |
+
|
| 675 |
+
function parseVTT(vttContent) {
|
| 676 |
+
const lines = vttContent.split('\n');
|
| 677 |
+
const lyricsData = [];
|
| 678 |
+
for (let i = 0; i < lines.length; i++) {
|
| 679 |
+
const match = lines[i].match(/(\d{2}:\d{2}:\d{2}\.\d{3}) --> (\d{2}:\d{2}:\d{2}\.\d{3})/);
|
| 680 |
+
if (match) {
|
| 681 |
+
let text = '';
|
| 682 |
+
let j = i + 1;
|
| 683 |
+
while (j < lines.length && lines[j].trim() !== '') {
|
| 684 |
+
text += lines[j] + '\n';
|
| 685 |
+
j++;
|
| 686 |
+
}
|
| 687 |
+
lyricsData.push({
|
| 688 |
+
start: timeToSeconds(match[1]),
|
| 689 |
+
end: timeToSeconds(match[2]),
|
| 690 |
+
text: text.trim().replace(/\[(.*?)\]/g, '<span class="lyrics-tag">[$1]</span>')
|
| 691 |
+
});
|
| 692 |
+
i = j;
|
| 693 |
+
}
|
| 694 |
+
}
|
| 695 |
+
return lyricsData;
|
| 696 |
}
|
| 697 |
|
| 698 |
+
function displayKaraokeLyrics(vttContent, audioEl) {
|
| 699 |
+
const lyricsData = parseVTT(vttContent);
|
| 700 |
finalLyricsBox.innerHTML = '';
|
| 701 |
+
lyricsData.forEach(line => {
|
| 702 |
+
const p = document.createElement('p');
|
| 703 |
+
p.className = 'lyrics-line';
|
| 704 |
+
p.innerHTML = line.text;
|
| 705 |
+
p.dataset.start = line.start;
|
| 706 |
+
p.dataset.end = line.end;
|
| 707 |
+
finalLyricsBox.appendChild(p);
|
| 708 |
+
});
|
| 709 |
|
| 710 |
+
let currentLine = null;
|
| 711 |
+
audioEl.addEventListener('timeupdate', () => {
|
| 712 |
+
const currentTime = audioEl.currentTime;
|
| 713 |
+
const lines = finalLyricsBox.children;
|
| 714 |
+
let found = false;
|
| 715 |
+
for (let i = 0; i < lines.length; i++) {
|
| 716 |
+
const line = lines[i];
|
| 717 |
+
if (currentTime >= line.dataset.start && currentTime <= line.dataset.end) {
|
| 718 |
+
if (line !== currentLine) {
|
| 719 |
+
if (currentLine) currentLine.classList.remove('active');
|
| 720 |
+
line.classList.add('active');
|
| 721 |
+
currentLine = line;
|
| 722 |
+
line.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 723 |
}
|
| 724 |
+
found = true;
|
| 725 |
+
break;
|
| 726 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 727 |
}
|
| 728 |
+
if (!found && currentLine) {
|
| 729 |
+
currentLine.classList.remove('active');
|
| 730 |
+
currentLine = null;
|
| 731 |
+
}
|
| 732 |
+
});
|
| 733 |
}
|
| 734 |
|
| 735 |
const canvas = document.getElementById('music-canvas');
|