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, suppliedSrc){ const src = suppliedSrc ? suppliedSrc : imgEl.src; const res = await fetch(src); const blob = await res.blob(); const imgId = Date.now() % 200; const isPng = !!imgEl; if(isPng){ const fileName = `controlnet-3d-pose-${imgId}.png`; return new File([blob], fileName, { type: 'image/png' }); }else{ const fileName = `controlnet-3d-pose-${imgId}.jpg`; return new File([blob], fileName, { type: 'image/jpeg' }); } } // const gradioEl = document.querySelector('body > gradio-app'); const gradioEl = document.querySelector("gradio-app"); const inputTxt = gradioEl.querySelector('#prompt input').value; const imgEls = gradioEl.querySelectorAll('#gallery img'); const poseMakerEl = gradioEl.querySelector("pose-maker"); const three_d_base64 = poseMakerEl.captureScreenshot(); const three_d_file = await getInputImgFile(null, three_d_base64); const three_d_url = await uploadFile(three_d_file); if(!inputTxt || !imgEls.length){ return; }; const files = await Promise.all( [...imgEls].map(async (imgEl) => getInputImgFile(imgEl, null)) ); const urls = await Promise.all(files.map((f) => uploadFile(f))); const htmlImgs = urls.map(url => ``); const titleLength = 150; let titleTxt = inputTxt; if(titleTxt.length > titleLength){ titleTxt = titleTxt.slice(0, titleLength) + ' ...'; } 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 descriptionMd = `### Prompt: ${inputTxt} ### 3D Pose: ### Renderings:
${htmlImgs.join(`\n`)}
`; const params = { title: titleTxt, description: descriptionMd, }; const paramsStr = Object.entries(params) .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`) .join('&'); window.open(`https://huggingface.co/spaces/diffusers/controlnet-3d-pose/discussions/new?${paramsStr}`, '_blank'); shareBtnEl.style.removeProperty('pointer-events'); shareIconEl.style.removeProperty('display'); loadingIconEl.style.display = 'none'; }""" share_btn_css = """ a {text-decoration-line: underline; font-weight: 600;} .animate-spin { animation: spin 1s linear infinite; } @keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } #share-btn-container { display: flex; padding-left: 0.5rem !important; padding-right: 0.5rem !important; background-color: #000000; justify-content: center; align-items: center; border-radius: 9999px !important; width: 13rem; } #share-btn { all: initial; color: #ffffff;font-weight: 600; cursor:pointer; font-family: 'IBM Plex Sans', sans-serif; margin-left: 0.5rem !important; padding-top: 0.25rem !important; padding-bottom: 0.25rem !important; } #share-btn * { all: unset; } #share-btn-container div:nth-child(-n+2){ width: auto !important; min-height: 0px !important; } #share-btn-container .wrap { display: none !important; } """