community_icon_html = """""" loading_icon_html = """""" share_js = """async () => { function isMobile() { try { document.createEvent("TouchEvent"); return true; } catch(e) { return false; } } 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; } var gradioEl = document.querySelector('body > gradio-app').shadowRoot; if (!gradioEl) { gradioEl = document.querySelector('body > gradio-app'); } const imgEls = gradioEl.querySelectorAll('#gallery .overflow-hidden'); const promptTxt = 'my perfect work'; const shareBtnEl = gradioEl.querySelector('#share-btn'); const shareIconEl = gradioEl.querySelector('#share-btn-share-icon'); const loadingIconEl = gradioEl.querySelector('#share-btn-loading-icon'); if(!imgEls.length){ return; }; shareBtnEl.style.pointerEvents = 'none'; shareIconEl.style.display = 'none'; loadingIconEl.style.removeProperty('display'); if (isMobile()) { gradioEl.querySelector('#platform_radio').querySelectorAll('input')[1].checked = true; } var files = []; var nowTime = Date.now(); var imgCount = 0; await Promise.all( [...imgEls].map(async (imgEl) => { if (imgEl.offsetWidth > 50 && imgEl.offsetHeight > 50) { const res = await fetch(imgEl.src); const blob = await res.blob(); const fileName = `img-cleaner-${nowTime}-${imgCount}.png`; imgCount += 1; files.push(new File([blob], fileName, { type: 'image/png'})); } }) ); const urls = await Promise.all(files.map((f) => uploadFile(f))); const htmlImgs = urls.map(url => ``); const descriptionMd = `
${htmlImgs.join(`\n`)}
`; const params = new URLSearchParams({ title: promptTxt, description: descriptionMd, }); const paramsStr = params.toString(); window.open(`https://huggingface.co/spaces/yizhangliu/ImgCleaner/discussions/new?${paramsStr}`, '_blank'); shareBtnEl.style.removeProperty('pointer-events'); shareIconEl.style.removeProperty('display'); loadingIconEl.style.display = 'none'; }"""