# Modified from https://huggingface.co/spaces/haoheliu/audioldm-text-to-audio-generation/blob/79681cd8cb235160a27cdd100673346eb1784e53/share_btn.py
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;
}
//Creating dynamic link that automatically click
function downloadURI(uri, name) {
var link = document.createElement("a");
link.download = name;
link.href = uri;
link.click();
}
//Your modified code.
function printToFile(div) {
html2canvas(div, {
onrendered: function (canvas) {
var myImage = canvas.toDataURL("image/png");
downloadURI("data:" + myImage, "fromage_chat.png");
}
});
}
const gradioEl = document.querySelector("gradio-app").shadowRoot || document.querySelector('body > gradio-app');
const chatbotEl = gradioEl.querySelector('#chatbot')
printToFile(chatbotEl)
const inputPromptEl = "test test";
//const outputChatbot = await getInputVideoFile(outputVideoEl);
//const urlChatbotImage = await uploadFile(outputChatbot);
const urlChatbotImage = "placeholder";
let titleTxt = `FROMAGe: ${inputPromptEl}`;
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 = `
## ${inputPromptEl}
${urlChatbotImage}
`;
const params = new URLSearchParams({
title: titleTxt,
description: descriptionMd,
});
const paramsStr = params.toString();
window.open(`https://huggingface.co/spaces/jykoh/fromage/discussions/new?${paramsStr}`, '_blank');
shareBtnEl.style.removeProperty('pointer-events');
shareIconEl.style.removeProperty('display');
loadingIconEl.style.display = 'none';
}"""