anzorq commited on
Commit
9273d53
1 Parent(s): c0884a0

Update share_btn.py

Browse files
Files changed (1) hide show
  1. share_btn.py +71 -73
share_btn.py CHANGED
@@ -9,78 +9,76 @@ style = "color: #ffffff;
9
  xmlns = "http://www.w3.org/2000/svg" xmlns: xlink = "http://www.w3.org/1999/xlink" aria - hidden="true" fill = "none" focusable = "false" role = "img" width = "1em" height = "1em" preserveAspectRatio = "xMidYMid meet" viewBox = "0 0 24 24" ><circle style="opacity: 0.25;" cx="12" cy="12" r="10" stroke="white" stroke-width="4"></circle><path style="opacity: 0.75;" fill="white" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg > """
10
 
11
  share_js = """async () => {
12
-
13
- // console.log('share button clicked');
14
-
15
- async function uploadFile(file) {
16
- const UPLOAD_URL = 'https://huggingface.co/uploads';
17
- const response = await fetch(UPLOAD_URL, {
18
- method: 'POST',
19
- headers: {
20
- 'Content-Type': file.type,
21
- 'X-Requested-With': 'XMLHttpRequest',
22
- },
23
- body: file, /// <- File inherits from Blob
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  });
25
- const url = await response.text();
26
- return url;
27
- }
28
-
29
- async function getVideoFile(videoEl) {
30
- const res = await fetch(videoEl.src);
31
- const blob = await res.blob();
32
- const videoId = Date.now() % 200;
33
- const fileName = `video-${{ videoId }}.mp4`;
34
- const file = new File([blob], fileName, { type: 'video/mp4' });
35
- console.log(file);
36
- return file;
37
- }
38
-
39
-
40
- const gradioAppEL = document.querySelector('body > gradio-app');
41
-
42
- const prompt_1 = gradioAppEL.querySelector('#riff-prompt_1 textarea').value;
43
- const prompt_2 = gradioAppEL.querySelector('#riff-prompt_2 textarea').value;
44
- const feel = gradioAppEL.querySelector("#riff-feel select").value;
45
- const seed = gradioAppEL.querySelector("#riff-seed input").value;
46
-
47
- const videoEl = gradioAppEL.querySelector('#riff-video video');
48
-
49
- const title = prompt_2 ? `From ${prompt_1} to ${prompt_2}` : prompt_1;
50
-
51
- const shareBtnEl = gradioAppEL.querySelector('#share-btn');
52
- const shareIconEl = gradioAppEL.querySelector('#share-btn-share-icon');
53
- const loadingIconEl = gradioAppEL.querySelector('#share-btn-loading-icon');
54
-
55
- if (!videoEl) {
56
- return;
57
- };
58
-
59
- shareBtnEl.style.pointerEvents = 'none';
60
- shareIconEl.style.display = 'none';
61
- loadingIconEl.style.removeProperty('display');
62
-
63
- const video = await getVideoFile(videoEl);
64
-
65
- const descriptionMdVideo = `Prompt: ${title}
66
- Feel: ${feel}
67
- Seed: ${seed}
68
-
69
- #### Video:
70
-
71
- <video controls>
72
- <source src="${video}" type="video/mp4">
73
- Your browser does not support the video element.
74
- </video>
75
- `;
76
-
77
- const params = new URLSearchParams({
78
- title: title,
79
- description: descriptionMd,
80
- });
81
- const paramsStr = params.toString();
82
- window.open(`https://huggingface.co/spaces/anzorq/riffusion-demo/discussions/new?${paramsStr}`, '_blank');
83
- shareBtnEl.style.removeProperty('pointer-events');
84
- shareIconEl.style.removeProperty('display');
85
- loadingIconEl.style.display = 'none';
86
  }"""
 
9
  xmlns = "http://www.w3.org/2000/svg" xmlns: xlink = "http://www.w3.org/1999/xlink" aria - hidden="true" fill = "none" focusable = "false" role = "img" width = "1em" height = "1em" preserveAspectRatio = "xMidYMid meet" viewBox = "0 0 24 24" ><circle style="opacity: 0.25;" cx="12" cy="12" r="10" stroke="white" stroke-width="4"></circle><path style="opacity: 0.75;" fill="white" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"></path></svg > """
10
 
11
  share_js = """async () => {
12
+
13
+ async function uploadFile(file) {
14
+ const UPLOAD_URL = 'https://huggingface.co/uploads';
15
+ const response = await fetch(UPLOAD_URL, {
16
+ method: 'POST',
17
+ headers: {
18
+ 'Content-Type': file.type,
19
+ 'X-Requested-With': 'XMLHttpRequest',
20
+ },
21
+ body: file, /// <- File inherits from Blob
22
+ });
23
+ const url = await response.text();
24
+ return url;
25
+ }
26
+
27
+ async function getVideoFile(videoEl) {
28
+ const res = await fetch(videoEl.src);
29
+ const blob = await res.blob();
30
+ const videoId = Date.now() % 200;
31
+ const fileName = `video-${{ videoId }}.mp4`;
32
+ const file = new File([blob], fileName, { type: 'video/mp4' });
33
+ console.log(file);
34
+ return file;
35
+ }
36
+
37
+
38
+ const gradioAppEL = document.querySelector('body > gradio-app');
39
+
40
+ const prompt_1 = gradioAppEL.querySelector('#riff-prompt_1 textarea').value;
41
+ const prompt_2 = gradioAppEL.querySelector('#riff-prompt_2 textarea').value;
42
+ const feel = gradioAppEL.querySelector("#riff-feel select").value;
43
+ const seed = gradioAppEL.querySelector("#riff-seed input").value;
44
+
45
+ const videoEl = gradioAppEL.querySelector('#riff-video video');
46
+
47
+ const title = prompt_2 ? `From ${prompt_1} to ${prompt_2}` : prompt_1;
48
+
49
+ const shareBtnEl = gradioAppEL.querySelector('#share-btn');
50
+ const shareIconEl = gradioAppEL.querySelector('#share-btn-share-icon');
51
+ const loadingIconEl = gradioAppEL.querySelector('#share-btn-loading-icon');
52
+
53
+ if (!videoEl) {
54
+ return;
55
+ };
56
+
57
+ shareBtnEl.style.pointerEvents = 'none';
58
+ shareIconEl.style.display = 'none';
59
+ loadingIconEl.style.removeProperty('display');
60
+
61
+ const video = await getVideoFile(videoEl);
62
+
63
+ const descriptionMd = `Prompt: ${title}
64
+ Feel: ${feel}
65
+ Seed: ${seed}
66
+
67
+ #### Video:
68
+
69
+ <video controls>
70
+ <source src="${video}" type="video/mp4">
71
+ Your browser does not support the video element.
72
+ </video>
73
+ `;
74
+
75
+ const params = new URLSearchParams({
76
+ title: title,
77
+ description: descriptionMd,
78
  });
79
+ const paramsStr = params.toString();
80
+ window.open(`https://huggingface.co/spaces/anzorq/riffusion-demo/discussions/new?${paramsStr}`, '_blank');
81
+ shareBtnEl.style.removeProperty('pointer-events');
82
+ shareIconEl.style.removeProperty('display');
83
+ loadingIconEl.style.display = 'none';
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  }"""