Opera8 commited on
Commit
7c66128
·
verified ·
1 Parent(s): d9573a6

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +71 -45
index.html CHANGED
@@ -656,13 +656,14 @@
656
  body: formData
657
  });
658
  const data = await response.json();
 
659
  if (data && data.length > 0) {
660
  return {
661
  "path": data[0],
662
  "url": `${ACE_SPACE_URL}gradio_api/file=${data[0]}`,
663
  "orig_name": file.name,
664
  "size": file.size,
665
- "mime_type": file.type,
666
  "meta": {"_type": "gradio.FileData"}
667
  };
668
  }
@@ -682,19 +683,7 @@
682
  loader.style.display = 'block';
683
 
684
  try {
685
- const audioInput = document.getElementById('audio_reference');
686
- let uploadedAudioObj = null;
687
-
688
- if (audioInput.files.length > 0) {
689
- let fileToUpload = audioInput.files[0];
690
- if (fileToUpload.type !== 'audio/wav' && !fileToUpload.name.toLowerCase().endsWith('.wav')) {
691
- loaderText.innerText = "در حال تبدیل فرمت فایل صوتی به WAV...";
692
- fileToUpload = await convertAudioToWav(fileToUpload);
693
- }
694
- loaderText.innerText = "در حال آپلود فایل نمونه...";
695
- uploadedAudioObj = await uploadAudioFile(fileToUpload);
696
- }
697
-
698
  loaderText.innerText = "آلفا در حال نوشتن شعر و ملودی...";
699
  const isInstrumental = getChk('instrumental_chk');
700
 
@@ -710,43 +699,68 @@
710
  });
711
 
712
  if (response.status === 429) {
713
- loader.style.display = 'none';
714
- step1.style.display = 'block';
715
- historySection.style.display = 'block';
716
- processBtn.disabled = false;
717
-
718
- upgradeModalTitle.innerText = "محدودیت ساخت روزانه";
719
- upgradeModalText.innerText = "شما به سقف ۵ آهنگ رایگان در روز رسیده‌اید.";
720
- upgradeModal.classList.add('open');
721
- return;
722
  }
723
 
724
  const data = await response.json();
725
  if (data.error) throw new Error(data.error);
726
 
727
  const { lyrics, musicPrompt } = data;
728
- loaderText.innerText = "در حال ضبط آهنگ در استودیو آلفا...";
729
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
730
  const finalLyrics = isInstrumental ? "" : lyrics;
731
 
732
- const taskType = uploadedAudioObj ? "prompt" : "text2music";
 
 
733
 
734
  const payload = [
735
- getVal('model_select'),
736
- "custom",
737
- uploadedAudioObj,
738
- getVal('duration_select'),
739
- musicPrompt,
740
- finalLyrics,
741
- 0, "", "", "unknown",
742
- getNum('steps_input'), getNum('cfg_input'), true, getNum('seed_input'), null, -1,
743
- getNum('batch_size'), null, null, 0, -1, "Fill the audio semantic mask based on the given conditions:",
744
- 1, taskType, false, 0, 1, 3, "ode", "", "mp3", 0.85,
745
- 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
 
 
 
 
 
 
 
746
  ];
747
 
748
  const session_hash = Math.random().toString(36).substring(2);
749
- 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 }) });
 
 
 
 
 
750
  if (!joinResp.ok) throw new Error('خطا در اتصال به سرور موزیک');
751
 
752
  const eventSource = new EventSource(`${ACE_SPACE_URL}gradio_api/queue/data?session_hash=${session_hash}`);
@@ -762,11 +776,21 @@
762
  eventSource.onerror = () => { throw new Error('ارتباط با سرور قطع شد.'); };
763
 
764
  } catch (e) {
765
- alert("خطا: " + e.message);
766
- loader.style.display = 'none';
767
- step1.style.display = 'block';
768
- historySection.style.display = 'block';
769
- processBtn.disabled = false;
 
 
 
 
 
 
 
 
 
 
770
  }
771
  });
772
 
@@ -790,11 +814,12 @@
790
  }
791
 
792
  function traverse(obj) {
 
793
  if (typeof obj === 'string') {
794
  if (obj.includes('/file=') && (obj.endsWith('.mp3') || obj.endsWith('.wav'))) {
795
  addAudio(obj);
796
  }
797
- } else if (obj && typeof obj === 'object') {
798
  if (obj.url && (obj.url.endsWith('.mp3') || obj.url.endsWith('.wav'))) {
799
  addAudio(obj.url);
800
  }
@@ -819,10 +844,11 @@
819
  finalLyricsBox.innerHTML = formatLyrics(lyrics);
820
  window.scrollTo({ top: 0, behavior: 'smooth' });
821
  } else {
822
- console.log("Server Response:", data);
823
- alert("فایل صوتی در پاسخ سرور یافت نشد. لطفاً دوباره تلاش کنید.");
824
  step1.style.display = 'block';
825
  historySection.style.display = 'block';
 
826
  }
827
  }
828
 
 
656
  body: formData
657
  });
658
  const data = await response.json();
659
+ // ** LOGIC FIX: Return full object structure expected by Gradio **
660
  if (data && data.length > 0) {
661
  return {
662
  "path": data[0],
663
  "url": `${ACE_SPACE_URL}gradio_api/file=${data[0]}`,
664
  "orig_name": file.name,
665
  "size": file.size,
666
+ "mime_type": "audio/wav",
667
  "meta": {"_type": "gradio.FileData"}
668
  };
669
  }
 
683
  loader.style.display = 'block';
684
 
685
  try {
686
+ // 1. Text Generation First
 
 
 
 
 
 
 
 
 
 
 
 
687
  loaderText.innerText = "آلفا در حال نوشتن شعر و ملودی...";
688
  const isInstrumental = getChk('instrumental_chk');
689
 
 
699
  });
700
 
701
  if (response.status === 429) {
702
+ throw new Error("LIMIT_REACHED");
 
 
 
 
 
 
 
 
703
  }
704
 
705
  const data = await response.json();
706
  if (data.error) throw new Error(data.error);
707
 
708
  const { lyrics, musicPrompt } = data;
 
709
 
710
+ // 2. Audio Upload (Only if file selected)
711
+ const audioInput = document.getElementById('audio_reference');
712
+ let uploadedAudioObj = null;
713
+
714
+ if (audioInput.files.length > 0) {
715
+ let fileToUpload = audioInput.files[0];
716
+ loaderText.innerText = "در حال پردازش فایل صوتی...";
717
+
718
+ if (fileToUpload.type !== 'audio/wav' && !fileToUpload.name.toLowerCase().endsWith('.wav')) {
719
+ fileToUpload = await convertAudioToWav(fileToUpload);
720
+ }
721
+
722
+ loaderText.innerText = "در حال آپلود فایل نمونه...";
723
+ uploadedAudioObj = await uploadAudioFile(fileToUpload);
724
+
725
+ if (!uploadedAudioObj) throw new Error("آپلود فایل با خطا مواجه شد.");
726
+ }
727
+
728
+ // 3. Generate Music
729
+ loaderText.innerText = "در حال ضبط آهنگ در استودیو آلفا...";
730
  const finalLyrics = isInstrumental ? "" : lyrics;
731
 
732
+ // ** CRITICAL FIX: Structure payload exactly as logs show **
733
+ // If audio exists, index 1 is "custom" and index 2 is object
734
+ // If no audio, index 1 is "custom" and index 2 is null (or check logs for no-audio case)
735
 
736
  const payload = [
737
+ getVal('model_select'), // 0: Model
738
+ "custom", // 1: Mode (Always "custom" based on logs)
739
+ uploadedAudioObj, // 2: Audio Object or null
740
+ getVal('duration_select'), // 3: Duration
741
+ musicPrompt, // 4: Prompt
742
+ finalLyrics, // 5: Lyrics
743
+ 0, "", "", "unknown", // 6-9
744
+ getNum('steps_input'), // 10: Steps
745
+ getNum('cfg_input'), // 11: CFG
746
+ true, // 12
747
+ getNum('seed_input'), // 13: Seed
748
+ null, -1, getNum('batch_size'), null, null, 0, -1,
749
+ "Fill the audio semantic mask based on the given conditions:", // 22
750
+ 1, // 23
751
+ "text2music", // 24: Task (Logs say text2music even with audio)
752
+ false, 0, 1, 3, "ode", "", "mp3", 0.85,
753
+ getChk('think_checkbox'), 2, 0, 0.9, "NO USER INPUT",
754
+ true, true, true, null, false, true, false, false, 0.5, 8, null, [], false, null, null, null, null
755
  ];
756
 
757
  const session_hash = Math.random().toString(36).substring(2);
758
+ const joinResp = await fetch(`${ACE_SPACE_URL}gradio_api/queue/join`, {
759
+ method: 'POST',
760
+ headers: { 'Content-Type': 'application/json' },
761
+ body: JSON.stringify({ data: payload, fn_index: 77, session_hash })
762
+ });
763
+
764
  if (!joinResp.ok) throw new Error('خطا در اتصال به سرور موزیک');
765
 
766
  const eventSource = new EventSource(`${ACE_SPACE_URL}gradio_api/queue/data?session_hash=${session_hash}`);
 
776
  eventSource.onerror = () => { throw new Error('ارتباط با سرور قطع شد.'); };
777
 
778
  } catch (e) {
779
+ if(e.message === "LIMIT_REACHED"){
780
+ loader.style.display = 'none';
781
+ step1.style.display = 'block';
782
+ historySection.style.display = 'block';
783
+ processBtn.disabled = false;
784
+ upgradeModalTitle.innerText = "محدودیت ساخت روزانه";
785
+ upgradeModalText.innerText = "شما به سقف ۵ آهنگ رایگان در روز رسیده‌اید.";
786
+ upgradeModal.classList.add('open');
787
+ } else {
788
+ alert("خطا: " + e.message);
789
+ loader.style.display = 'none';
790
+ step1.style.display = 'block';
791
+ historySection.style.display = 'block';
792
+ processBtn.disabled = false;
793
+ }
794
  }
795
  });
796
 
 
814
  }
815
 
816
  function traverse(obj) {
817
+ if (!obj) return;
818
  if (typeof obj === 'string') {
819
  if (obj.includes('/file=') && (obj.endsWith('.mp3') || obj.endsWith('.wav'))) {
820
  addAudio(obj);
821
  }
822
+ } else if (typeof obj === 'object') {
823
  if (obj.url && (obj.url.endsWith('.mp3') || obj.url.endsWith('.wav'))) {
824
  addAudio(obj.url);
825
  }
 
844
  finalLyricsBox.innerHTML = formatLyrics(lyrics);
845
  window.scrollTo({ top: 0, behavior: 'smooth' });
846
  } else {
847
+ console.log("Full Server Response for Debug:", data);
848
+ alert("خروجی معتبری دریافت نشد. لطفاً تنظیمات را بررسی کنید.");
849
  step1.style.display = 'block';
850
  historySection.style.display = 'block';
851
+ processBtn.disabled = false;
852
  }
853
  }
854