community_icon_html = """""" loading_icon_html = """""" share_js = r"""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, }); const url = await response.text(); return url; } function getButtonText(componentId) { const buttonEl = gradioEl.querySelector(`${componentId} button`); return buttonEl ? buttonEl.textContent : ''; } const gradioEl = document.querySelector('body > gradio-app'); const imgEls = [gradioEl.querySelector('#input_image img'), gradioEl.querySelector('#output_image img')]; const concepts = [ { value: getButtonText('#box1'), parent: gradioEl.querySelector('#box1 span[data-testid="block-info"]') }, { value: getButtonText('#box2'), parent: gradioEl.querySelector('#box2 span[data-testid="block-info"]') }, { value: getButtonText('#box3'), parent: gradioEl.querySelector('#box3 span[data-testid="block-info"]') } ]; const promptTxt = gradioEl.querySelector('#target_prompt input').value; const shareBtnEl = gradioEl.querySelector('#share-btn'); const shareIconEl = gradioEl.querySelector('#share-btn-share-icon'); const loadingIconEl = gradioEl.querySelector('#share-btn-loading-icon'); if(!imgEls[1]){ return; }; shareBtnEl.style.pointerEvents = 'none'; shareIconEl.style.display = 'none'; loadingIconEl.style.removeProperty('display'); async function processImage(imgEl, imgId) { const res = await fetch(imgEl.src); const blob = await res.blob(); const fileType = blob.type.includes('png') ? 'png' : 'jpg'; const fileName = `diffuse-the-rest-${imgId}.${fileType}`; return new File([blob], fileName, { type: blob.type }); } const files = await Promise.all(imgEls.map((imgEl, index) => processImage(imgEl, Date.now() + index % 200))); const urls = await Promise.all(files.map((file) => uploadFile(file))); const labels = ['Source image', 'Target image']; const htmlImgs = urls.map((url, index) => `