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 getOutputVideoFile(videoEL){
const res = await fetch(videoEL.src);
const blob = await res.blob();
const videoId = Date.now() % 200;
const fileName = `vid-pix2pix-${{videoId}}.wav`;
const videoBlob = new File([blob], fileName, { type: 'video/mp4' });
console.log(videoBlob);
return videoBlob;
}
const gradioEl = document.querySelector("gradio-app").shadowRoot || document.querySelector('body > gradio-app');
const captionTxt = gradioEl.querySelector('#prompt-in textarea').value;
const inputVidEl = gradioEl.querySelector('#input-vid video');
const outputVideo = gradioEl.querySelector('#video-output video');
const shareBtnEl = gradioEl.querySelector('#share-btn');
const shareIconEl = gradioEl.querySelector('#share-btn-share-icon');
const loadingIconEl = gradioEl.querySelector('#share-btn-loading-icon');
if(!outputVideo){
return;
};
shareBtnEl.style.pointerEvents = 'none';
shareIconEl.style.display = 'none';
loadingIconEl.style.removeProperty('display');
const inputFile = await getInputFile(inputVidEl);
const urlInputVid = await uploadFile(inputFile);
const videoOutFile = await getInputFile(outputVideo);
const dataOutputVid = await uploadFile(videoOutFile);
const descriptionMd = `
#### Video input:
${urlInputVid}
#### Pix2Pix result:
${dataOutputVid}
`;
const params = new URLSearchParams({
title: captionTxt,
description: descriptionMd,
});
const paramsStr = params.toString();
window.open(`https://huggingface.co/spaces/fffiloni/Pix2Pix-Video/discussions/new?${paramsStr}`, '_blank');
shareBtnEl.style.removeProperty('pointer-events');
shareIconEl.style.removeProperty('display');
loadingIconEl.style.display = 'none';
}"""