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 getInputVideoFile(videoEl){ const res = await fetch(videoEl.src); const blob = await res.blob(); const videoId = Date.now() % 200; const fileName = `sd-perception-${{videoId}}.mp4`; return new File([blob], fileName, { type: 'video/mp4' }); } async function audioToBase64(audioFile) { return new Promise((resolve, reject) => { let reader = new FileReader(); reader.readAsDataURL(audioFile); reader.onload = () => resolve(reader.result); reader.onerror = error => reject(error); }); } const gradioEl = document.querySelector("gradio-app").shadowRoot || document.querySelector('body > gradio-app'); const inputPromptEl = gradioEl.querySelector('#prompt-in input').value; const outputVideoEl = gradioEl.querySelector('#output-video video'); let titleTxt = `Text-to-Audio: ${inputPromptEl}`; const shareBtnEl = gradioEl.querySelector('#share-btn'); const shareIconEl = gradioEl.querySelector('#share-btn-share-icon'); const loadingIconEl = gradioEl.querySelector('#share-btn-loading-icon'); if(!outputVideoEl){ return; }; shareBtnEl.style.pointerEvents = 'none'; shareIconEl.style.display = 'none'; loadingIconEl.style.removeProperty('display'); const outputVideo = await getInputVideoFile(outputVideoEl); const urlOutputVideo = await uploadFile(outputVideo); const descriptionMd = ` ##### ${inputPromptEl} ${urlOutputVideo} `; const params = new URLSearchParams({ title: titleTxt, description: descriptionMd, }); const paramsStr = params.toString(); window.open(`https://huggingface.co/spaces/haoheliu/AudioLDM_48K_Text-to-HiFiAudio_Generation/discussions/new?${paramsStr}`, '_blank'); shareBtnEl.style.removeProperty('pointer-events'); shareIconEl.style.removeProperty('display'); loadingIconEl.style.display = 'none'; }"""