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': 'video/mp4',
'X-Requested-With': 'XMLHttpRequest',
},
body: file, /// <- File inherits from Blob
});
const url = await response.text();
return url;
}
async function getOutputVideoFile(videoURL){
fetch(videoURL, {mode: 'no-cors'})
.then(response => response.blob())
.then(blob => {
// do something with the blob;
console.log(blob);
let videoBlob = URL.createObjectURL(blob);
console.log(videoBlob);
return videoBlob;
});
}
//const gradioEl = document.querySelector('body > gradio-app');
const gradioEl = document.querySelector("gradio-app").shadowRoot;
const whisper_input = gradioEl.querySelector('#text_inp textarea').value;
const outputVideo = gradioEl.querySelector('#video_out video');
const outputVideo_src = gradioEl.querySelector('#video_out video').src;
console.log(outputVideo_src)
const outputVideo_name = outputVideo_src.split('/').pop();
const video_url = `https://fffiloni-gpt-talking-portrait.hf.space/file=https://fffiloni-one-shot-talking-face.hf.space/file=/tmp/${outputVideo_name}`;
let titleTxt = outputVideo_name;
//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');
if(!outputVideo){
return;
};
shareBtnEl.style.pointerEvents = 'none';
shareIconEl.style.display = 'none';
loadingIconEl.style.removeProperty('display');
const videoFile = await getOutputVideoFile(outputVideo_src);
//const dataOutputVideo = await uploadFile(videoFile);
const descriptionMd = `
#### What i asked for:
${whisper_input}
#### Video:
`;
const params = new URLSearchParams({
title: titleTxt,
description: descriptionMd,
});
const paramsStr = params.toString();
window.open(`https://huggingface.co/spaces/fffiloni/gpt-talking-portrait/discussions/new?${paramsStr}`, '_blank');
shareBtnEl.style.removeProperty('pointer-events');
shareIconEl.style.removeProperty('display');
loadingIconEl.style.display = 'none';
}"""