Update index.html
Browse files- index.html +23 -7
index.html
CHANGED
|
@@ -729,8 +729,7 @@
|
|
| 729 |
|
| 730 |
const finalLyrics = isInstrumental ? "" : lyrics;
|
| 731 |
|
| 732 |
-
// ** LOGIC
|
| 733 |
-
// If audio is uploaded, we must switch the task from "text2music" to "prompt" (or equivalent for conditioning)
|
| 734 |
const taskType = uploadedAudioObj ? "prompt" : "text2music";
|
| 735 |
|
| 736 |
const payload = [
|
|
@@ -777,6 +776,7 @@
|
|
| 777 |
let hasResult = false;
|
| 778 |
|
| 779 |
function addAudio(url) {
|
|
|
|
| 780 |
const fullUrl = url.startsWith('http') ? url : ACE_SPACE_URL.replace(/\/$/, '') + url;
|
| 781 |
if (processedUrls.has(fullUrl)) return;
|
| 782 |
processedUrls.add(fullUrl);
|
|
@@ -790,14 +790,30 @@
|
|
| 790 |
playerWrapper.innerHTML += `<div class="audio-item"><audio controls autoplay src="${fullUrl}"></audio></div>`;
|
| 791 |
}
|
| 792 |
|
|
|
|
| 793 |
function traverse(obj) {
|
| 794 |
-
if (typeof obj === 'string'
|
| 795 |
-
|
| 796 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 797 |
Object.values(obj).forEach(traverse);
|
| 798 |
}
|
| 799 |
}
|
| 800 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 801 |
|
| 802 |
if (hasResult) {
|
| 803 |
const headerText = document.getElementById('resultHeaderText');
|
|
@@ -807,7 +823,7 @@
|
|
| 807 |
finalLyricsBox.innerHTML = formatLyrics(lyrics);
|
| 808 |
window.scrollTo({ top: 0, behavior: 'smooth' });
|
| 809 |
} else {
|
| 810 |
-
alert("فایل صوتی یافت نشد!");
|
| 811 |
step1.style.display = 'block';
|
| 812 |
historySection.style.display = 'block';
|
| 813 |
}
|
|
|
|
| 729 |
|
| 730 |
const finalLyrics = isInstrumental ? "" : lyrics;
|
| 731 |
|
| 732 |
+
// ** LOGIC FIX: Switch task mode based on audio input **
|
|
|
|
| 733 |
const taskType = uploadedAudioObj ? "prompt" : "text2music";
|
| 734 |
|
| 735 |
const payload = [
|
|
|
|
| 776 |
let hasResult = false;
|
| 777 |
|
| 778 |
function addAudio(url) {
|
| 779 |
+
if (!url) return;
|
| 780 |
const fullUrl = url.startsWith('http') ? url : ACE_SPACE_URL.replace(/\/$/, '') + url;
|
| 781 |
if (processedUrls.has(fullUrl)) return;
|
| 782 |
processedUrls.add(fullUrl);
|
|
|
|
| 790 |
playerWrapper.innerHTML += `<div class="audio-item"><audio controls autoplay src="${fullUrl}"></audio></div>`;
|
| 791 |
}
|
| 792 |
|
| 793 |
+
// Enhanced Traversal to find nested audio files
|
| 794 |
function traverse(obj) {
|
| 795 |
+
if (typeof obj === 'string') {
|
| 796 |
+
if (obj.includes('/file=') && (obj.endsWith('.mp3') || obj.endsWith('.wav'))) {
|
| 797 |
+
addAudio(obj);
|
| 798 |
+
}
|
| 799 |
+
} else if (obj && typeof obj === 'object') {
|
| 800 |
+
if (obj.url && (obj.url.endsWith('.mp3') || obj.url.endsWith('.wav'))) {
|
| 801 |
+
addAudio(obj.url);
|
| 802 |
+
}
|
| 803 |
+
if (obj.path && (obj.path.endsWith('.mp3') || obj.path.endsWith('.wav'))) {
|
| 804 |
+
// Sometimes 'path' is local, need to prepend gradio_api/file=
|
| 805 |
+
addAudio(`/gradio_api/file=${obj.path}`);
|
| 806 |
+
}
|
| 807 |
Object.values(obj).forEach(traverse);
|
| 808 |
}
|
| 809 |
}
|
| 810 |
+
|
| 811 |
+
// Check data structure carefully
|
| 812 |
+
if (data && data.data) {
|
| 813 |
+
data.data.forEach(item => traverse(item));
|
| 814 |
+
} else {
|
| 815 |
+
traverse(data);
|
| 816 |
+
}
|
| 817 |
|
| 818 |
if (hasResult) {
|
| 819 |
const headerText = document.getElementById('resultHeaderText');
|
|
|
|
| 823 |
finalLyricsBox.innerHTML = formatLyrics(lyrics);
|
| 824 |
window.scrollTo({ top: 0, behavior: 'smooth' });
|
| 825 |
} else {
|
| 826 |
+
alert("فایل صوتی یافت نشد! (خروجی سرور خالی بود)");
|
| 827 |
step1.style.display = 'block';
|
| 828 |
historySection.style.display = 'block';
|
| 829 |
}
|