community_icon_html = """""" loading_icon_html = """""" share_js = """async () => { async function uploadFile(file){ const UPLOAD_URL = 'https://huggingface.co/uploads'; const response = await fetch(UPLOAD_URL, { method: 'POST', headers: { 'Content-Type': file.type, 'X-Requested-With': 'XMLHttpRequest', }, body: file, /// <- File inherits from Blob }); const url = await response.text(); return url; } async function getOutputMusicFile(audioEL){ const res = await fetch(audioEL.src); const blob = await res.blob(); const audioId = Date.now() % 200; const fileName = `SVS-${{audioId}}.wav`; const musicBlob = new File([blob], fileName, { type: 'audio/wav' }); return musicBlob; } const gradioEl = document.querySelector('body > gradio-app'); //const gradioEl = document.querySelector("gradio-app").shadowRoot; const inputSinger = gradioEl.querySelector('#inp_singer select').value; const inputText = gradioEl.querySelector('#inp_text textarea').value; const inputNote = gradioEl.querySelector('#inp_note textarea').value; const inputDuration = gradioEl.querySelector('#inp_duration textarea').value; const outputMusic = gradioEl.querySelector('#music-output audio'); const outputMusic_src = gradioEl.querySelector('#music-output audio').src; const outputMusic_name = outputMusic_src.split('/').pop(); let titleTxt = outputMusic_name; if(titleTxt.length > 30){ titleTxt = 'demo'; } const shareBtnEl = gradioEl.querySelector('#share-btn'); const shareIconEl = gradioEl.querySelector('#share-btn-share-icon'); const loadingIconEl = gradioEl.querySelector('#share-btn-loading-icon'); if(!outputMusic){ return; }; shareBtnEl.style.pointerEvents = 'none'; shareIconEl.style.display = 'none'; loadingIconEl.style.removeProperty('display'); const musicFile = await getOutputMusicFile(outputMusic); const dataOutputMusic = await uploadFile(musicFile); const descriptionMd = `#### Input Musical Score: ${inputSinger} ${inputText} ${inputNote} ${inputDuration} #### Singing Voice: `; const params = new URLSearchParams({ title: titleTxt, description: descriptionMd, }); const paramsStr = params.toString(); window.open(`https://huggingface.co/spaces/zlc99/M4Singer/discussions/new?${paramsStr}`, '_blank'); shareBtnEl.style.removeProperty('pointer-events'); shareIconEl.style.removeProperty('display'); loadingIconEl.style.display = 'none'; }"""