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' });
}
}
console.log("test")
const gradioEl = document.querySelector("gradio-app").shadowRoot || document.querySelector('body > gradio-app');
const randomLoRA_1 = gradioEl.querySelector('#component-7 img');
const randomLoRA_1_title = gradioEl.querySelector('#component-7 [data-testid="block-label"] span').innerHTML
const randomLoRA_2 = gradioEl.querySelector('#component-7 img')
const randomLoRA_2_title = gradioEl.querySelector('component-7 [data-testid="block-label"] span').innerHTML
const prompt = gradioEl.querySelector('#prompt textarea').value
const outputImgEl = gradioEl.querySelector('#component-22 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 inputLoRA_1 = await getInputImgFile(randomLoRA_1);
const urlLoRA1 = await uploadFile(inputLoRA_1);
const inputLoRA_2 = await getInputImgFile(randomLoRA_2);
const urlLoRA2 = await uploadFile(inputLoRA_2);
const descriptionMd = `
| {randomLoRA_1_title} | | {randomLoRA_2_title}|
|---------|-----------|---------|
| ![{randomLoRA_1_title}]({urlLoRA1}) | + | ![{randomLoRA_1_title}]({urlLoRA2}) |
### Prompt
${inputPrompt}
#### Generated Image:
`;
console.log(descriptionMd)
const params = new URLSearchParams({
title: prompt,
description: descriptionMd,
preview: true
});
const paramsStr = params.toString();
window.open(`https://huggingface.co./spaces/multimodalart/lora-roulette/discussions/new?${paramsStr}`, '_blank');
shareBtnEl.style.removeProperty('pointer-events');
shareIconEl.style.removeProperty('display');
loadingIconEl.style.display = 'none';
}"""