Hector Salvador [Fisharp] commited on
Commit
4f9e345
1 Parent(s): 2bc3f5c

Temp remove share.js to allow renaming the .py one

Browse files
Files changed (1) hide show
  1. static/share_btn.js +0 -75
static/share_btn.js DELETED
@@ -1,75 +0,0 @@
1
- async () => {
2
- async function uploadFile(file) {
3
- const UPLOAD_URL = 'https://huggingface.co/uploads';
4
- const response = await fetch(UPLOAD_URL, {
5
- method: 'POST',
6
- headers: {
7
- 'Content-Type': file.type,
8
- 'X-Requested-With': 'XMLHttpRequest',
9
- },
10
- body: file, /// <- File inherits from Blob
11
- });
12
- const url = await response.text();
13
- return url;
14
- }
15
-
16
- async function getInputImgFile(imgEl) {
17
- const res = await fetch(imgEl.src);
18
- const blob = await res.blob();
19
- const imgId = Date.now() % 200;
20
- const isPng = imgEl.src.startsWith(`data:image/png`);
21
- if (isPng) {
22
- const fileName = `sd-perception-${{ imgId }}.png`;
23
- return new File([blob], fileName, { type: 'image/png' });
24
- } else {
25
- const fileName = `sd-perception-${{ imgId }}.jpg`;
26
- return new File([blob], fileName, { type: 'image/jpeg' });
27
- }
28
- }
29
-
30
- // const gradioEl = document.querySelector('body > gradio-app');
31
- const gradioEl = document.querySelector("gradio-app");
32
- const inputTxt = gradioEl.querySelector('#q-input textarea').value;
33
- let outputTxt = gradioEl.querySelector('#q-output .codemirror-wrapper .cm-scroller > div:nth-of-type(2)').innerText;
34
- outputTxt = `<pre>${outputTxt}</pre>`
35
-
36
- const titleLength = 150;
37
- let titleTxt = inputTxt;
38
- if (titleTxt.length > titleLength) {
39
- titleTxt = titleTxt.slice(0, titleLength) + ' ...';
40
- }
41
-
42
- const shareBtnEl = gradioEl.querySelector('#share-btn');
43
- const shareIconEl = gradioEl.querySelector('#share-btn-share-icon');
44
- const loadingIconEl = gradioEl.querySelector('#share-btn-loading-icon');
45
-
46
- if (!inputTxt || !outputTxt) {
47
- return;
48
- };
49
-
50
- shareBtnEl.style.pointerEvents = 'none';
51
- shareIconEl.style.display = 'none';
52
- loadingIconEl.style.removeProperty('display');
53
-
54
- const descriptionMd = `### Question:
55
- ${inputTxt}
56
-
57
- ### Answer:
58
-
59
- ${outputTxt}`;
60
-
61
- const params = {
62
- title: titleTxt,
63
- description: descriptionMd,
64
- };
65
-
66
- const paramsStr = Object.entries(params)
67
- .map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
68
- .join('&');
69
-
70
- window.open(`https://huggingface.co/spaces/fisharp/starcoder-playground/discussions/new?${paramsStr}`, '_blank');
71
-
72
- shareBtnEl.style.removeProperty('pointer-events');
73
- shareIconEl.style.removeProperty('display');
74
- loadingIconEl.style.display = 'none';
75
- }