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; } const gradioEl = document.querySelector('body > gradio-app'); const audioEl = gradioEl.querySelector('audio'); const resultTxt = gradioEl.querySelector('#result-textarea textarea').value; const shareBtnEl = gradioEl.querySelector('#share-btn'); const shareIconEl = gradioEl.querySelector('#share-btn-share-icon'); const loadingIconEl = gradioEl.querySelector('#share-btn-loading-icon'); if(!audioEl){ return; }; shareBtnEl.style.pointerEvents = 'none'; shareIconEl.style.display = 'none'; loadingIconEl.style.removeProperty('display'); const res = await fetch(audioEl.src); const blob = await res.blob(); const audioId = Date.now() % 200; const fileName = `whisper-${{audioId}}.wav`; const audioFile = new File([blob], fileName, { type: 'audio/wav' }); const url = await uploadFile(audioFile); const descriptionMd = `#### Input audio: #### Transcription: ${resultTxt}`; const params = new URLSearchParams({ description: descriptionMd, }); const paramsStr = params.toString(); window.open(`https://huggingface.co/spaces/openai/whisper/discussions/new?${paramsStr}`, '_blank'); shareBtnEl.style.removeProperty('pointer-events'); shareIconEl.style.removeProperty('display'); loadingIconEl.style.display = 'none'; }"""