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 getInputImageFile(imageEl){
const res = await fetch(imageEl.src);
const blob = await res.blob();
const imageId = Date.now();
const fileName = `rich-text-image-${{imageId}}.png`;
return new File([blob], fileName, { type: 'image/png'});
}
const gradioEl = document.querySelector("gradio-app").shadowRoot || document.querySelector('body > gradio-app');
const negative_prompt = gradioEl.querySelector('#negative-prompt-text-input input').value;
const prompt = gradioEl.querySelector('#prompt-text-input input').value;
const upscaledImage = gradioEl.querySelector('#upscaled-image img');
const titleTxt = `DeepFloyd IF: ${prompt.slice(0, 50)}...`;
const shareBtnEl = gradioEl.querySelector('#share-btn');
const shareIconEl = gradioEl.querySelector('#share-btn-share-icon');
const loadingIconEl = gradioEl.querySelector('#share-btn-loading-icon');
if(!upscaledImage){
return;
};
shareBtnEl.style.pointerEvents = 'none';
shareIconEl.style.display = 'none';
loadingIconEl.style.removeProperty('display');
const upscaledImageFile = await getInputImageFile(upscaledImage);
const upscaledImageURL = await uploadFile(upscaledImageFile);
const descriptionMd = `
### Prompt
${prompt}
### Negative Prompt
${negative_prompt}
### Upscaled Image
`;
const params = new URLSearchParams({
title: titleTxt,
description: descriptionMd,
});
const paramsStr = params.toString();
window.open(`https://huggingface.co/spaces/DeepFloyd/IF/discussions/new?${paramsStr}`, '_blank');
shareBtnEl.style.removeProperty('pointer-events');
shareIconEl.style.removeProperty('display');
loadingIconEl.style.display = 'none';
}"""