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 getInputImgFile(imgEl){ const res = await fetch(imgEl.src); const blob = await res.blob(); const imgId = Date.now() % 200; const isPng = imgEl.src.startsWith(`data:image/png`); if(isPng){ const fileName = `sd-perception-${{imgId}}.png`; return new File([blob], fileName, { type: 'image/png' }); }else{ const fileName = `sd-perception-${{imgId}}.jpg`; return new File([blob], fileName, { type: 'image/jpeg' }); } } const gradioEl = document.querySelector("gradio-app").shadowRoot || document.querySelector('body > gradio-app'); const inputPrompt = gradioEl.querySelector('#prompt textarea').value; const negativePrompt = gradioEl.querySelector('#negative_prompt textarea').value; const controlImage = gradioEl.querySelector('#control_image img'); const outputImgEl = gradioEl.querySelector('#output img'); const shareBtnEl = gradioEl.querySelector('#share-btn'); const shareIconEl = gradioEl.querySelector('#share-btn-share-icon'); const loadingIconEl = gradioEl.querySelector('#share-btn-loading-icon'); shareBtnEl.style.pointerEvents = 'none'; shareIconEl.style.display = 'none'; loadingIconEl.style.removeProperty('display'); const inputFile = await getInputImgFile(outputImgEl); const urlInputImg = await uploadFile(inputFile); const controlFile = await getInputImgFile(controlImage); const urlControlImg = await uploadFile(controlFile); const descriptionMd = ` ### Prompt - *Prompt*: ${inputPrompt} - *Negative prompt*: ${negativePrompt} #### Generated Image: #### Control Image: `; const params = new URLSearchParams({ title: inputPrompt, description: descriptionMd, preview: true }); const paramsStr = params.toString(); window.open(`https://huggingface.co/spaces/multimodalart/LoraTheExplorer/discussions/new?${paramsStr}`, '_blank'); shareBtnEl.style.removeProperty('pointer-events'); shareIconEl.style.removeProperty('display'); loadingIconEl.style.display = 'none'; }"""