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 getVideoFile(videoEl) {
const res = await fetch(videoEl.src);
const blob = await res.blob();
const videoId = Date.now() % 200;
const fileName = `video-${{ videoId }}.mp4`;
const file = new File([blob], fileName, { type: 'video/mp4' });
console.log(file);
return file;
}
const gradioAppEL = document.querySelector('body > gradio-app');
const prompt_1 = gradioAppEL.querySelector('#riff-prompt_1 textarea').value;
const prompt_2 = gradioAppEL.querySelector('#riff-prompt_2 textarea').value;
const feel = gradioAppEL.querySelector("#riff-feel select").value;
const seed = gradioAppEL.querySelector("#riff-seed input").value;
const videoEl = gradioAppEL.querySelector('#riff-video video');
const title = prompt_2 ? `From ${prompt_1} to ${prompt_2}` : prompt_1;
const shareBtnEl = gradioAppEL.querySelector('#share-btn');
const shareIconEl = gradioAppEL.querySelector('#share-btn-share-icon');
const loadingIconEl = gradioAppEL.querySelector('#share-btn-loading-icon');
if (!videoEl) {
return;
};
shareBtnEl.style.pointerEvents = 'none';
shareIconEl.style.display = 'none';
loadingIconEl.style.removeProperty('display');
const video = await getVideoFile(videoEl);
const descriptionMd = `Prompt: ${title}
Feel: ${feel}
Seed: ${seed}
#### Video:
`;
const params = new URLSearchParams({
title: title,
description: descriptionMd,
});
const paramsStr = params.toString();
window.open(`https://huggingface.co/spaces/anzorq/riffusion-demo/discussions/new?${paramsStr}`, '_blank');
shareBtnEl.style.removeProperty('pointer-events');
shareIconEl.style.removeProperty('display');
loadingIconEl.style.display = 'none';
}"""