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 = `zero123++_${{imgId}}.png`;
            return new File([blob], fileName, { type: 'image/png' });
        }else{
            const fileName = `zero123++_${{imgId}}.jpg`;
            return new File([blob], fileName, { type: 'image/jpeg' });
        }
	}
    
    const gradioEl = document.querySelector("gradio-app").shadowRoot || document.querySelector('body > gradio-app');
    const inputPrompt = "Multiviews generated by Zero123++";
    const seed = gradioEl.querySelector('#seed input[type="number"]').value;
    const scale = gradioEl.querySelector('#scale input[type="number"]').value;
    const num_steps = gradioEl.querySelector('#num_steps input[type="number"]').value;
    const controlImage = gradioEl.querySelector('#input_image img');
    const outputImgEl = gradioEl.querySelector('#six_view 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 outputFile = await getInputImgFile(outputImgEl);
    const urlOutputImg = await uploadFile(outputFile);
    const controlFile = await getInputImgFile(controlImage);
    const urlControlImg = await uploadFile(controlFile);
    
    const descriptionMd = `
#### Generated Multiviews:
 #### Input Image:
#### Input Image: 
 #### Parameters: 
- *Seed*: ${seed}
- *Classifier Free Guidance Scale*: ${scale}
- *Number of Diffusion Inference Steps*: ${num_steps}
`;
    const params = new URLSearchParams({
        title: inputPrompt,
        description: descriptionMd,
        preview: true
    });
	const paramsStr = params.toString();
	window.open(`https://huggingface.co/spaces/sudo-ai/zero123plus-demo-space/discussions/new?${paramsStr}`, '_blank');
    shareBtnEl.style.removeProperty('pointer-events');
    shareIconEl.style.removeProperty('display');
    loadingIconEl.style.display = 'none';
}"""
#### Parameters: 
- *Seed*: ${seed}
- *Classifier Free Guidance Scale*: ${scale}
- *Number of Diffusion Inference Steps*: ${num_steps}
`;
    const params = new URLSearchParams({
        title: inputPrompt,
        description: descriptionMd,
        preview: true
    });
	const paramsStr = params.toString();
	window.open(`https://huggingface.co/spaces/sudo-ai/zero123plus-demo-space/discussions/new?${paramsStr}`, '_blank');
    shareBtnEl.style.removeProperty('pointer-events');
    shareIconEl.style.removeProperty('display');
    loadingIconEl.style.display = 'none';
}"""