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 getOutputImgFile(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('body > gradio-app');
    const outputImgEl = gradioEl.querySelector('#output-img img');
    
    //const outputImg_src = outputImgEl.src;
    //const outputImg_name = outputImg_src.split('/').pop();
    //let titleTxt = outputImg_name;
    
    let titleTxt = gradioEl.querySelector('#input-prompt > label > textarea').placeholder;
    if(titleTxt.length > 100){
        titleTxt = titleTxt.slice(0, 100) + ' ...';
    }
    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 getOutputImgFile(outputImgEl);
    const urlOutputImg = await uploadFile(outputFile);
    
    const descriptionMd = `#### Output Image:
 This is my cool character! Made with Cyberpunk Anime Diffusion AI!
`;
    const params = new URLSearchParams({
        title: titleTxt,
        description: descriptionMd,
    });
	const paramsStr = params.toString();
	window.open(`https://huggingface.co/spaces/DGSpitzer/DGS-Diffusion-Space/discussions/new?${paramsStr}`, '_blank');
    shareBtnEl.style.removeProperty('pointer-events');
    shareIconEl.style.removeProperty('display');
    loadingIconEl.style.display = 'none';
    console.log(gradioEl.querySelector('#input-prompt'));
}"""
This is my cool character! Made with Cyberpunk Anime Diffusion AI!
`;
    const params = new URLSearchParams({
        title: titleTxt,
        description: descriptionMd,
    });
	const paramsStr = params.toString();
	window.open(`https://huggingface.co/spaces/DGSpitzer/DGS-Diffusion-Space/discussions/new?${paramsStr}`, '_blank');
    shareBtnEl.style.removeProperty('pointer-events');
    shareIconEl.style.removeProperty('display');
    loadingIconEl.style.display = 'none';
    console.log(gradioEl.querySelector('#input-prompt'));
}"""