beeguy commited on
Commit
7a26dd9
·
1 Parent(s): 0d3c10a

button for download

Browse files
Files changed (2) hide show
  1. static/index.html +1 -0
  2. static/script.js +28 -3
static/index.html CHANGED
@@ -24,6 +24,7 @@
24
  <label for="text-gen-input">Text prompt</label>
25
  <input id="text-gen-input" type="text" value="English: Translate There are many ducks. German:" />
26
  <button id="text-gen-submit">Submit</button>
 
27
  <p class="text-gen-output"></p>
28
  </form>
29
  </section>
 
24
  <label for="text-gen-input">Text prompt</label>
25
  <input id="text-gen-input" type="text" value="English: Translate There are many ducks. German:" />
26
  <button id="text-gen-submit">Submit</button>
27
+ <button id="download-embeddings" type="button">Download Embeddings</button>
28
  <p class="text-gen-output"></p>
29
  </form>
30
  </section>
static/script.js CHANGED
@@ -1,10 +1,11 @@
1
  const textGenForm = document.querySelector('.text-gen-form');
 
2
 
3
  const embedText = async (text) => {
4
  const inferResponse = await fetch(`embeddings?input=${text}`);
5
  const inferJson = await inferResponse.json();
6
 
7
- return inferJson.output;
8
  };
9
 
10
  textGenForm.addEventListener('submit', async (event) => {
@@ -14,8 +15,32 @@ textGenForm.addEventListener('submit', async (event) => {
14
  const textGenParagraph = document.querySelector('.text-gen-output');
15
 
16
  try {
17
- textGenParagraph.textContent = await embedText(textGenInput.value);
 
 
 
18
  } catch (err) {
19
  console.error(err);
20
  }
21
- });
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  const textGenForm = document.querySelector('.text-gen-form');
2
+ let embeddingsList = [];
3
 
4
  const embedText = async (text) => {
5
  const inferResponse = await fetch(`embeddings?input=${text}`);
6
  const inferJson = await inferResponse.json();
7
 
8
+ return inferJson.embeddings;
9
  };
10
 
11
  textGenForm.addEventListener('submit', async (event) => {
 
15
  const textGenParagraph = document.querySelector('.text-gen-output');
16
 
17
  try {
18
+ const embeddings = await embedText(textGenInput.value);
19
+ embeddingsList = embeddings; // Store embeddings in the variable
20
+ textGenParagraph.textContent = JSON.stringify(embeddingsList);
21
+ updateDownloadButtonState(); // Update button state
22
  } catch (err) {
23
  console.error(err);
24
  }
25
+ });
26
+
27
+ const downloadButton = document.getElementById('download-embeddings');
28
+
29
+ const updateDownloadButtonState = () => {
30
+ downloadButton.disabled = embeddingsList.length === 0;
31
+ };
32
+
33
+ const downloadEmbeddings = () => {
34
+ const dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(embeddingsList));
35
+ const downloadAnchorNode = document.createElement('a');
36
+ downloadAnchorNode.setAttribute("href", dataStr);
37
+ downloadAnchorNode.setAttribute("download", "embeddings.json");
38
+ document.body.appendChild(downloadAnchorNode);
39
+ downloadAnchorNode.click();
40
+ downloadAnchorNode.remove();
41
+ };
42
+
43
+ downloadButton.addEventListener('click', downloadEmbeddings);
44
+
45
+ // Initialize button state
46
+ updateDownloadButtonState();