dylanebert HF staff commited on
Commit
16289c7
·
1 Parent(s): 369f59c

remove internal

Browse files
viewer/src/routes/+page.svelte CHANGED
@@ -2,9 +2,7 @@
2
  import { onMount } from "svelte";
3
  import SvelteTable, { type TableColumn } from "svelte-table";
4
  import Row from "./Row";
5
- import EditButtonComponent from "./EditButtonComponent.svelte";
6
- import EditModal from "./EditModal.svelte";
7
- import { fetchRows, addEntry } from "./bridge";
8
  import { statusMessage } from "./store";
9
  import SearchButtonComponent from "./SearchButtonComponent.svelte";
10
 
@@ -62,14 +60,6 @@
62
  parseHTML: true,
63
  hideFilterHeader: true,
64
  },
65
- {
66
- key: "Edit",
67
- title: "",
68
- value: (v: Row) => "",
69
- sortable: false,
70
- renderComponent: EditButtonComponent,
71
- hideFilterHeader: true,
72
- },
73
  {
74
  key: "Search",
75
  title: "",
@@ -78,29 +68,6 @@
78
  renderComponent: SearchButtonComponent,
79
  hideFilterHeader: true,
80
  },
81
- {
82
- key: "ReachedOut",
83
- title: "Reached Out",
84
- value: (v: Row) => {
85
- if (v.Tags.includes("ReachedOut")) {
86
- return "\u2705";
87
- } else if (v.Tags.includes("NoReachedOut")) {
88
- return "\u274C";
89
- } else {
90
- return "";
91
- }
92
- },
93
- sortable: true,
94
- filterValue: (v: Row) => {
95
- if (v.Tags.includes("ReachedOut")) {
96
- return "Yes";
97
- } else if (v.Tags.includes("NoReachedOut")) {
98
- return "N/A";
99
- }
100
- return "No";
101
- },
102
- filterOptions: ["Yes", "No", "N/A"],
103
- },
104
  {
105
  key: "Date",
106
  title: "Date",
@@ -280,25 +247,6 @@
280
  },
281
  parseHTML: true,
282
  },
283
- {
284
- key: "Added",
285
- title: "Added",
286
- value: (v: Row) => v.Added || "",
287
- sortable: true,
288
- searchValue: (v: Row) => v.Added || "",
289
- renderValue: (v: Row) => {
290
- if (!v.Added) return "";
291
- let renderDate = v.Added;
292
-
293
- // Convert ISO to YYYY-MM-DD
294
- if (v.Added.includes("T")) {
295
- renderDate = v.Added.split("T")[0];
296
- }
297
-
298
- return `<span title="${v.Added}">${renderDate}</span>`;
299
- },
300
- parseHTML: true,
301
- },
302
  ];
303
 
304
  let selection: Record<string | number, any> = {};
@@ -336,22 +284,7 @@
336
  refreshRows();
337
  });
338
 
339
- async function newEntry() {
340
- const row = await addEntry(selection);
341
- if (!row) return;
342
- rows = [row, ...rows];
343
- }
344
-
345
- function handleRowUpdated(event: Event) {
346
- refreshRows();
347
- }
348
-
349
- function handleRowDeleted(event: Event) {
350
- refreshRows();
351
- }
352
-
353
  let fetching = false;
354
- let isModalOpen = false;
355
  </script>
356
 
357
  {#if fetching}
@@ -359,32 +292,12 @@
359
  <p>{@html $statusMessage}</p>
360
  </div>
361
  {:else}
362
- <div style="text-align: center; margin-top: 1rem;">
363
- <input
364
- type="text"
365
- placeholder="Enter relevant project, code, paper, space, model, or dataset URL"
366
- style="width: 100%; max-width: 512px;"
367
- bind:value={searchValue}
368
- />
369
- <button on:click={newEntry}>New Entry</button>
370
- </div>
371
-
372
- {#if statusMessage}
373
- <div style="text-align: center; margin-top: 0.5rem;">
374
- {#if !isModalOpen}
375
- {@html $statusMessage}
376
- {/if}
377
- </div>
378
- {/if}
379
-
380
  <!--spacer-->
381
  <div style="height: 1rem;" />
382
 
383
  <SvelteTable {columns} {rows} bind:sortBy bind:sortOrder bind:filterSelections={selection} />
384
  {/if}
385
 
386
- <EditModal bind:isOpen={isModalOpen} on:rowUpdated={handleRowUpdated} on:rowDeleted={handleRowDeleted} />
387
-
388
  <style>
389
  :global(td) {
390
  border-top: 1px solid #e0e0e0;
 
2
  import { onMount } from "svelte";
3
  import SvelteTable, { type TableColumn } from "svelte-table";
4
  import Row from "./Row";
5
+ import { fetchRows } from "./bridge";
 
 
6
  import { statusMessage } from "./store";
7
  import SearchButtonComponent from "./SearchButtonComponent.svelte";
8
 
 
60
  parseHTML: true,
61
  hideFilterHeader: true,
62
  },
 
 
 
 
 
 
 
 
63
  {
64
  key: "Search",
65
  title: "",
 
68
  renderComponent: SearchButtonComponent,
69
  hideFilterHeader: true,
70
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
71
  {
72
  key: "Date",
73
  title: "Date",
 
247
  },
248
  parseHTML: true,
249
  },
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
250
  ];
251
 
252
  let selection: Record<string | number, any> = {};
 
284
  refreshRows();
285
  });
286
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
287
  let fetching = false;
 
288
  </script>
289
 
290
  {#if fetching}
 
292
  <p>{@html $statusMessage}</p>
293
  </div>
294
  {:else}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
295
  <!--spacer-->
296
  <div style="height: 1rem;" />
297
 
298
  <SvelteTable {columns} {rows} bind:sortBy bind:sortOrder bind:filterSelections={selection} />
299
  {/if}
300
 
 
 
301
  <style>
302
  :global(td) {
303
  border-top: 1px solid #e0e0e0;
viewer/src/routes/EditButtonComponent.svelte DELETED
@@ -1,15 +0,0 @@
1
- <script lang="ts">
2
- import { editingRow } from "./store";
3
- import Row from "./Row";
4
-
5
- export let row: Row;
6
- export let col;
7
-
8
- let key = col.key;
9
-
10
- function onEditButtonClick(row: Row) {
11
- editingRow.set(row);
12
- }
13
- </script>
14
-
15
- <button on:click={() => onEditButtonClick(row)}>{key}</button>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
viewer/src/routes/EditModal.svelte DELETED
@@ -1,239 +0,0 @@
1
- <script lang="ts">
2
- import { onDestroy, createEventDispatcher } from "svelte";
3
- import { editingRow, statusMessage } from "./store";
4
- import type Row from "./Row";
5
- import { inferFields, editEntry, deleteEntry } from "./bridge";
6
-
7
- const dispatch = createEventDispatcher();
8
- let row: Row | null = null;
9
-
10
- export let isOpen = false;
11
-
12
- const unsubscribe = editingRow.subscribe((value: Row | null) => {
13
- row = value;
14
- isOpen = !!value;
15
- if (!isOpen) {
16
- statusMessage.reset();
17
- }
18
- });
19
-
20
- async function saveEntry() {
21
- if (!row) return;
22
- statusMessage.set(`<span>Sending edit request to backend...</span>`);
23
-
24
- const result = await editEntry(row);
25
- if (!result) return;
26
- dispatch("rowUpdated", row);
27
- }
28
-
29
- async function tryInfer() {
30
- if (!row) return;
31
- const result = await inferFields(row);
32
- if (!result) return;
33
- editingRow.set(result);
34
- }
35
-
36
- async function tryDelete() {
37
- if (!row) return;
38
- statusMessage.set(`<span style="color: red">Sending delete request to backend...</span>`);
39
- const result = await deleteEntry(row);
40
- if (!result) return;
41
- dispatch("rowDeleted", row);
42
- close();
43
- }
44
-
45
- function close() {
46
- editingRow.set(null);
47
- }
48
-
49
- onDestroy(unsubscribe);
50
- </script>
51
-
52
- {#if $editingRow}
53
- <div class="modal">
54
- <button class="modal-backdrop" on:click={close} />
55
- <div class="modal-content">
56
- <button class="close-button" on:click={close}> &times; </button>
57
- <h2>Edit Entry</h2>
58
- <div class="button-group">
59
- <button class="delete-button" on:click={tryDelete}>Delete Entry</button>
60
- </div>
61
- {#if row}
62
- <div class="input-group">
63
- <label for="name">Name</label>
64
- <input id="name" bind:value={row.Name} />
65
- </div>
66
- <div class="input-group">
67
- <label for="added">Added</label>
68
- <input id="added" bind:value={row.Added} />
69
- </div>
70
- <div class="input-group">
71
- <label for="date">Date</label>
72
- <input id="date" bind:value={row.Date} />
73
- </div>
74
- <div class="input-group">
75
- <label for="orgs">Orgs</label>
76
- <input id="orgs" bind:value={row.Orgs} />
77
- </div>
78
- <div class="input-group">
79
- <label for="authors">Authors</label>
80
- <input id="authors" bind:value={row.Authors} />
81
- </div>
82
- <div class="input-group">
83
- <label for="paper">Paper</label>
84
- <input id="paper" bind:value={row.Paper} />
85
- </div>
86
- <div class="input-group">
87
- <label for="code">Code</label>
88
- <input id="code" bind:value={row.Code} />
89
- </div>
90
- <div class="input-group">
91
- <label for="project">Project</label>
92
- <input id="project" bind:value={row.Project} />
93
- </div>
94
- <div class="input-group">
95
- <label for="space">Space</label>
96
- <input id="space" bind:value={row.Space} />
97
- </div>
98
- <div class="input-group">
99
- <label for="model">Model</label>
100
- <input id="model" bind:value={row.Model} />
101
- </div>
102
- <div class="input-group">
103
- <label for="dataset">Dataset</label>
104
- <input id="dataset" bind:value={row.Dataset} />
105
- </div>
106
- <div class="input-group">
107
- <label for="license">License</label>
108
- <input id="license" bind:value={row.License} />
109
- </div>
110
- <div class="input-group">
111
- <label for="code-status">Code Status</label>
112
- <input id="code-status" bind:value={row.CodeStatus} />
113
- </div>
114
- <div class="input-group">
115
- <label for="tags">Tags</label>
116
- <input id="tags" bind:value={row.Tags} />
117
- </div>
118
- {/if}
119
- <div class="button-group">
120
- <button class="infer-button" on:click={tryInfer}>Infer Fields</button>
121
- <button class="save-button" on:click={saveEntry}>Save</button>
122
- </div>
123
- <div class="status">
124
- <span>{@html $statusMessage}</span>
125
- </div>
126
- </div>
127
- </div>
128
- {/if}
129
-
130
- <style>
131
- .modal {
132
- position: fixed;
133
- top: 0;
134
- left: 0;
135
- z-index: 1000;
136
- width: 100%;
137
- height: 100%;
138
- background-color: rgba(0, 0, 0, 0.5);
139
- display: flex;
140
- justify-content: center;
141
- align-items: center;
142
- }
143
-
144
- .modal-backdrop {
145
- position: absolute;
146
- top: 0;
147
- left: 0;
148
- z-index: -1;
149
- width: 100%;
150
- height: 100%;
151
- background-color: transparent;
152
- border: none;
153
- }
154
-
155
- .modal-content {
156
- position: relative;
157
- background-color: white;
158
- padding: 20px;
159
- border-radius: 5px;
160
- width: 50%;
161
- max-width: 768px;
162
- }
163
-
164
- .modal-content h2 {
165
- margin: 0;
166
- margin-bottom: 10px;
167
- }
168
-
169
- .input-group {
170
- display: flex;
171
- justify-content: space-between;
172
- margin-bottom: 10px;
173
- }
174
-
175
- .input-group label {
176
- flex: 1;
177
- margin-right: 10px;
178
- }
179
-
180
- .input-group input {
181
- flex: 2;
182
- }
183
-
184
- .modal-content input {
185
- width: 100%;
186
- }
187
-
188
- .close-button {
189
- position: absolute;
190
- top: 10px;
191
- right: 10px;
192
- background: none;
193
- border: none;
194
- font-size: 1.5em;
195
- cursor: pointer;
196
- }
197
-
198
- .button-group {
199
- margin: 10px 0;
200
- width: 100%;
201
- display: flex;
202
- justify-content: left;
203
- }
204
-
205
- .infer-button {
206
- background-color: rgb(68, 127, 215);
207
- color: white;
208
- border: none;
209
- padding: 5px 10px;
210
- border-radius: 5px;
211
- cursor: pointer;
212
- flex: 1;
213
- }
214
-
215
- .save-button {
216
- background-color: #53c457;
217
- color: white;
218
- border: none;
219
- padding: 5px 10px;
220
- border-radius: 5px;
221
- cursor: pointer;
222
- flex: 1;
223
- }
224
-
225
- .delete-button {
226
- background-color: rgb(248, 39, 39);
227
- color: white;
228
- border: none;
229
- padding: 5px 10px;
230
- border-radius: 5px;
231
- cursor: pointer;
232
- }
233
-
234
- .status {
235
- width: 100%;
236
- text-align: center;
237
- margin: 10px 0;
238
- }
239
- </style>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
viewer/src/routes/api/request/+server.ts DELETED
@@ -1,14 +0,0 @@
1
- export const POST = async ({ request }) => {
2
- const endpoint = request.headers.get("endpoint");
3
- const row = await request.json();
4
- const response = await fetch(`https://dylanebert-research-tracker-backend.hf.space/${endpoint}`, {
5
- method: "POST",
6
- headers: {
7
- "Content-Type": "application/json",
8
- Authorization: "Bearer " + import.meta.env.VITE_HF_TOKEN,
9
- },
10
- body: JSON.stringify(row),
11
- });
12
- const data = await response.json();
13
- return new Response(JSON.stringify(data));
14
- };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
viewer/src/routes/bridge.ts CHANGED
@@ -16,516 +16,3 @@ export const fetchRows = async (): Promise<Row[] | null> => {
16
  return null;
17
  }
18
  };
19
-
20
- export const addEntry = async (selection: Record<string | number, any>): Promise<Row | null> => {
21
- if (!("Name" in selection)) return null;
22
- const value = selection["Name"] as string;
23
- let row: Row | null = new Row();
24
- const field = await inferFieldType(row, value);
25
- if (!field) return null;
26
- if (field === "Name") {
27
- row.Name = value;
28
- } else if (field === "Paper") {
29
- row.Paper = value;
30
- } else if (field === "Code") {
31
- row.Code = value;
32
- } else if (field === "Space") {
33
- row.Space = value;
34
- } else if (field === "Model") {
35
- row.Model = value;
36
- } else if (field === "Dataset") {
37
- row.Dataset = value;
38
- } else if (field === "Project") {
39
- row.Project = value;
40
- } else {
41
- statusMessage.set(`<span style="color: red;">Error: Failed to infer field type for <b>${value}</b></span>`);
42
- return null;
43
- }
44
- row = await inferFields(row);
45
- if (!row) {
46
- return null;
47
- }
48
- const response = await fetch("/api/request", {
49
- method: "POST",
50
- headers: {
51
- "Content-Type": "application/json",
52
- endpoint: "add-entry",
53
- },
54
- body: JSON.stringify(row),
55
- });
56
- const data = await response.json();
57
- if (data.error || !data.success) {
58
- if (data.error) {
59
- statusMessage.append(`<br><span style="color: red;">Error: ${data.error}</span>`);
60
- } else {
61
- statusMessage.append(`<br><span style="color: red;">Error: Failed to add entry</span>`);
62
- }
63
- return null;
64
- }
65
- statusMessage.append(`<br><span style="color: green;">Added entry for "${row.Name}"</span>`);
66
-
67
- return row;
68
- };
69
-
70
- export const editEntry = async (row: Row): Promise<Row | null> => {
71
- row.Orgs = Array.isArray(row.Orgs) ? row.Orgs : (row.Orgs as any).split(",").map((org: string) => org.trim());
72
- row.Authors = Array.isArray(row.Authors)
73
- ? row.Authors
74
- : (row.Authors as any).split(",").map((author: string) => author.trim());
75
- row.Tags = Array.isArray(row.Tags) ? row.Tags : (row.Tags as any).split(",").map((tag: string) => tag.trim());
76
- const response = await fetch("/api/request", {
77
- method: "POST",
78
- headers: {
79
- "Content-Type": "application/json",
80
- endpoint: "edit-entry",
81
- },
82
- body: JSON.stringify(row),
83
- });
84
- const data = await response.json();
85
- if (data.error || !data.success) {
86
- if (data.error) {
87
- statusMessage.append(`<br><span style="color: red;">Error: ${data.error}</span>`);
88
- } else {
89
- statusMessage.append(`<br><span style="color: red;">Error: Failed to edit entry</span>`);
90
- }
91
- return null;
92
- }
93
- statusMessage.append(`<br><span style="color: green;">Edited entry for "${row.Name}"</span>`);
94
- return row;
95
- };
96
-
97
- export const deleteEntry = async (row: Row): Promise<Row | null> => {
98
- row.Orgs = Array.isArray(row.Orgs) ? row.Orgs : (row.Orgs as any).split(",").map((org: string) => org.trim());
99
- row.Authors = Array.isArray(row.Authors)
100
- ? row.Authors
101
- : (row.Authors as any).split(",").map((author: string) => author.trim());
102
- row.Tags = Array.isArray(row.Tags) ? row.Tags : (row.Tags as any).split(",").map((tag: string) => tag.trim());
103
- const response = await fetch("/api/request", {
104
- method: "POST",
105
- headers: {
106
- "Content-Type": "application/json",
107
- endpoint: "delete-entry",
108
- },
109
- body: JSON.stringify(row),
110
- });
111
- const data = await response.json();
112
- if (data.error || !data.success) {
113
- if (data.error) {
114
- statusMessage.append(`<br><span style="color: red;">Error: ${data.error}</span>`);
115
- } else {
116
- statusMessage.append(`<br><span style="color: red;">Error: Failed to delete entry</span>`);
117
- }
118
- return null;
119
- }
120
- statusMessage.append(`<br><span style="color: green;">Deleted entry for "${row.Name}"</span>`);
121
- return row;
122
- };
123
-
124
- export const inferFields = async (row: Row): Promise<Row | null> => {
125
- const key = row.Name || row.Paper || row.Code || row.Space || row.Model || row.Dataset || row.Project;
126
- statusMessage.set(`<span>Inferring fields for <b>${key}</b></span>`);
127
- const paper = row.Paper || (await inferPaper(row));
128
- const code = row.Code || (await inferCode(row));
129
- const name = row.Name || (await inferName(row));
130
- if (!name) {
131
- return null;
132
- }
133
- row.Name = name;
134
- const authors = row.Authors.length == 0 ? await inferAuthors(row) : row.Authors;
135
- const orgs = row.Orgs.length == 0 ? await inferOrgs(row) : row.Orgs;
136
- const date = row.Date || (await inferDate(row));
137
- const model = row.Model || (await inferModel(row));
138
- const dataset = row.Dataset || (await inferDataset(row));
139
- const space = row.Space || (await inferSpace(row));
140
- const license = row.License || (await inferLicense(row));
141
- if (paper) {
142
- row.Paper = paper;
143
- }
144
- if (code) {
145
- row.Code = code;
146
- }
147
- if (authors) {
148
- row.Authors = Array.isArray(authors) ? authors : authors.split(",").map((author: string) => author.trim());
149
- }
150
- if (orgs) {
151
- row.Orgs = Array.isArray(orgs) ? orgs : orgs.split(",").map((org: string) => org.trim());
152
- }
153
- if (date) {
154
- row.Date = date;
155
- }
156
- if (model) {
157
- row.Model = model;
158
- }
159
- if (dataset) {
160
- row.Dataset = dataset;
161
- }
162
- if (space) {
163
- row.Space = space;
164
- }
165
- if (license) {
166
- row.License = license;
167
- }
168
- if (!row.Added) {
169
- row.Added = new Date().toISOString();
170
- }
171
- statusMessage.append(`<br><span style="color: green;">Finished inferring fields for <b>${row.Name}</b></span>`);
172
- return row;
173
- };
174
-
175
- const inferFieldType = async (row: Row, value: string): Promise<string | null> => {
176
- let data;
177
- try {
178
- const response = await fetch("/api/request", {
179
- method: "POST",
180
- headers: {
181
- "Content-Type": "application/json",
182
- endpoint: "infer-field",
183
- },
184
- body: JSON.stringify({ value }),
185
- });
186
- data = await response.json();
187
- } catch (e) {
188
- statusMessage.append(
189
- `<br><span style="color: red;">Error: Failed to infer field type for <b>${value}</b></span>`
190
- );
191
- return null;
192
- }
193
- if (data.error || !data.field || !(data.field in row)) {
194
- statusMessage.set(`<span style="color: red;">Error: Failed to infer field type for <b>${value}</b></span>`);
195
- return null;
196
- }
197
- statusMessage.set(`<span style="color: green;">Inferred field type: ${data.field}</span>`);
198
- return data.field;
199
- };
200
-
201
- const inferPaper = async (row: Row) => {
202
- statusMessage.append(`<br><span>Inferring paper...</span>`);
203
- let data;
204
- try {
205
- const response = await fetch("/api/request", {
206
- method: "POST",
207
- headers: {
208
- "Content-Type": "application/json",
209
- endpoint: "infer-paper",
210
- },
211
- body: JSON.stringify(row),
212
- });
213
- data = await response.json();
214
- } catch (e) {
215
- statusMessage.remove("<br><span>Inferring paper...</span>");
216
- statusMessage.append(`<br><span style="color: red;">Error: Failed to infer paper</span>`);
217
- return null;
218
- }
219
- statusMessage.remove("<br><span>Inferring paper...</span>");
220
- if (data.error || !data.paper) {
221
- if (data.error) {
222
- statusMessage.append(`<br><span style="color: red;">Error: ${data.error}</span>`);
223
- } else if (data.message) {
224
- statusMessage.append(`<br><span>${data.message}</span>`);
225
- } else {
226
- statusMessage.append(`<br><span style="color: red;">Error: Failed to infer paper</span>`);
227
- }
228
- return null;
229
- }
230
- const link = `<a href="${data.paper}" target="_blank">${data.paper}</a>`;
231
- statusMessage.append(`<br><span style="color: green;">Inferred paper: ${link}</span>`);
232
- return data.paper;
233
- };
234
-
235
- const inferCode = async (row: Row) => {
236
- statusMessage.append(`<br><span>Inferring code...</span>`);
237
- let data;
238
- try {
239
- const response = await fetch("/api/request", {
240
- method: "POST",
241
- headers: {
242
- endpoint: "infer-code",
243
- "Content-Type": "application/json",
244
- },
245
- body: JSON.stringify(row),
246
- });
247
- data = await response.json();
248
- } catch (e) {
249
- statusMessage.remove("<br><span>Inferring code...</span>");
250
- statusMessage.append(`<br><span style="color: red;">Error: Failed to infer code</span>`);
251
- return null;
252
- }
253
- statusMessage.remove("<br><span>Inferring code...</span>");
254
- if (data.error || !data.code) {
255
- if (data.error) {
256
- statusMessage.append(`<br><span style="color: red;">Error: ${data.error}</span>`);
257
- } else if (data.message) {
258
- statusMessage.append(`<br><span>${data.message}</span>`);
259
- } else {
260
- statusMessage.append(`<br><span style="color: red;">Error: Failed to infer code</span>`);
261
- }
262
- return null;
263
- }
264
- const link = `<a href="${data.code}" target="_blank">${data.code}</a>`;
265
- statusMessage.append(`<br><span style="color: green;">Inferred code: ${link}</span>`);
266
- return data.code;
267
- };
268
-
269
- const inferName = async (row: Row) => {
270
- statusMessage.append(`<br><span>Inferring name...</span>`);
271
- let data;
272
- try {
273
- const response = await fetch("/api/request", {
274
- method: "POST",
275
- headers: {
276
- endpoint: "infer-name",
277
- "Content-Type": "application/json",
278
- },
279
- body: JSON.stringify(row),
280
- });
281
- data = await response.json();
282
- } catch (e) {
283
- statusMessage.remove("<br><span>Inferring name...</span>");
284
- statusMessage.append(`<br><span style="color: red;">Error: Failed to infer name</span>`);
285
- return null;
286
- }
287
- statusMessage.remove("<br><span>Inferring name...</span>");
288
- if (data.error || !data.name) {
289
- if (data.error) {
290
- statusMessage.append(`<br><span style="color: red;">Error: ${data.error}</span>`);
291
- } else if (data.message) {
292
- statusMessage.append(`<br><span style="color: red;">Error: ${data.message}</span>`);
293
- } else {
294
- statusMessage.append(`<br><span style="color: red;">Error: Failed to infer name</span>`);
295
- }
296
- return null;
297
- }
298
- statusMessage.append(`<br><span style="color: green;">Inferred name: <b>${data.name}</b></span>`);
299
- return data.name;
300
- };
301
-
302
- const inferAuthors = async (row: Row) => {
303
- statusMessage.append(`<br><span>Inferring authors...</span>`);
304
- let data;
305
- try {
306
- const response = await fetch("/api/request", {
307
- method: "POST",
308
- headers: {
309
- endpoint: "infer-authors",
310
- "Content-Type": "application/json",
311
- },
312
- body: JSON.stringify(row),
313
- });
314
- data = await response.json();
315
- } catch (e) {
316
- statusMessage.remove("<br><span>Inferring authors...</span>");
317
- statusMessage.append(`<br><span style="color: red;">Error: Failed to infer authors</span>`);
318
- return null;
319
- }
320
- statusMessage.remove("<br><span>Inferring authors...</span>");
321
- if (data.error || !data.authors) {
322
- if (data.error) {
323
- statusMessage.append(`<br><span style="color: red;">Error: ${data.error}</span>`);
324
- } else if (data.message) {
325
- statusMessage.append(`<br><span>${data.message}</span>`);
326
- } else {
327
- statusMessage.append(`<br><span style="color: red;">Error: Failed to infer authors</span>`);
328
- }
329
- return null;
330
- }
331
- statusMessage.append(`<br><span style="color: green;">Inferred authors: ${data.authors}</span>`);
332
- return data.authors;
333
- };
334
-
335
- const inferOrgs = async (row: Row) => {
336
- statusMessage.append(`<br><span>Inferring orgs...</span>`);
337
- let data;
338
- try {
339
- const response = await fetch("/api/request", {
340
- method: "POST",
341
- headers: {
342
- endpoint: "infer-orgs",
343
- "Content-Type": "application/json",
344
- },
345
- body: JSON.stringify(row),
346
- });
347
- data = await response.json();
348
- } catch (e) {
349
- statusMessage.remove("<br><span>Inferring orgs...</span>");
350
- statusMessage.append(`<br><span style="color: red;">Error: Failed to infer orgs</span>`);
351
- return null;
352
- }
353
- statusMessage.remove("<br><span>Inferring orgs...</span>");
354
- if (data.error || !data.orgs) {
355
- if (data.error) {
356
- statusMessage.append(`<br><span style="color: red;">Error: ${data.error}</span>`);
357
- } else if (data.message) {
358
- statusMessage.append(`<br><span>${data.message}</span>`);
359
- } else {
360
- statusMessage.append(`<br><span style="color: red;">Error: Failed to infer orgs</span>`);
361
- }
362
- return null;
363
- }
364
- statusMessage.append(`<br><span style="color: green;">Inferred orgs: ${data.orgs}</span>`);
365
- return data.orgs;
366
- };
367
-
368
- const inferDate = async (row: Row) => {
369
- statusMessage.append(`<br><span>Inferring date...</span>`);
370
- let data;
371
- try {
372
- const response = await fetch("/api/request", {
373
- method: "POST",
374
- headers: {
375
- endpoint: "infer-date",
376
- "Content-Type": "application/json",
377
- },
378
- body: JSON.stringify(row),
379
- });
380
- data = await response.json();
381
- } catch (e) {
382
- statusMessage.remove("<br><span>Inferring date...</span>");
383
- statusMessage.append(`<br><span style="color: red;">Error: Failed to infer date</span>`);
384
- return null;
385
- }
386
- statusMessage.remove("<br><span>Inferring date...</span>");
387
- if (data.error || !data.date) {
388
- if (data.error) {
389
- statusMessage.append(`<br><span style="color: red;">Error: ${data.error}</span>`);
390
- } else if (data.message) {
391
- statusMessage.append(`<br><span>${data.message}</span>`);
392
- } else {
393
- statusMessage.append(`<br><span style="color: red;">Error: Failed to infer date</span>`);
394
- }
395
- return null;
396
- }
397
- statusMessage.append(`<br><span style="color: green;">Inferred date: ${data.date}</span>`);
398
- return data.date;
399
- };
400
-
401
- const inferModel = async (row: Row) => {
402
- statusMessage.append(`<br><span>Inferring model...</span>`);
403
- let data;
404
- try {
405
- const response = await fetch("/api/request", {
406
- method: "POST",
407
- headers: {
408
- endpoint: "infer-model",
409
- "Content-Type": "application/json",
410
- },
411
- body: JSON.stringify(row),
412
- });
413
- data = await response.json();
414
- } catch (e) {
415
- statusMessage.remove("<br><span>Inferring model...</span>");
416
- statusMessage.append(`<br><span style="color: red;">Error: Failed to infer model</span>`);
417
- return null;
418
- }
419
- statusMessage.remove("<br><span>Inferring model...</span>");
420
- if (data.error || !data.model) {
421
- if (data.error) {
422
- statusMessage.append(`<br><span style="color: red;">Error: ${data.error}</span>`);
423
- } else if (data.message) {
424
- statusMessage.append(`<br><span>${data.message}</span>`);
425
- } else {
426
- statusMessage.append(`<br><span style="color: red;">Error: Failed to infer model</span>`);
427
- }
428
- return null;
429
- }
430
- statusMessage.append(`<br><span style="color: green;">Inferred model: ${data.model}</span>`);
431
- return data.model;
432
- };
433
-
434
- const inferDataset = async (row: Row) => {
435
- statusMessage.append(`<br><span>Inferring dataset...</span>`);
436
- let data;
437
- try {
438
- const response = await fetch("/api/request", {
439
- method: "POST",
440
- headers: {
441
- endpoint: "infer-dataset",
442
- "Content-Type": "application/json",
443
- },
444
- body: JSON.stringify(row),
445
- });
446
- data = await response.json();
447
- } catch (e) {
448
- statusMessage.remove("<br><span>Inferring dataset...</span>");
449
- statusMessage.append(`<br><span style="color: red;">Error: Failed to infer dataset</span>`);
450
- return null;
451
- }
452
- statusMessage.remove("<br><span>Inferring dataset...</span>");
453
- if (data.error || !data.dataset) {
454
- if (data.error) {
455
- statusMessage.append(`<br><span style="color: red;">Error: ${data.error}</span>`);
456
- } else if (data.message) {
457
- statusMessage.append(`<br><span>${data.message}</span>`);
458
- } else {
459
- statusMessage.append(`<br><span style="color: red;">Error: Failed to infer dataset</span>`);
460
- }
461
- return null;
462
- }
463
- statusMessage.append(`<br><span style="color: green;">Inferred dataset: ${data.dataset}</span>`);
464
- return data.dataset;
465
- };
466
-
467
- const inferSpace = async (row: Row) => {
468
- statusMessage.append(`<br><span>Inferring space...</span>`);
469
- let data;
470
- try {
471
- const response = await fetch("/api/request", {
472
- method: "POST",
473
- headers: {
474
- endpoint: "infer-space",
475
- "Content-Type": "application/json",
476
- },
477
- body: JSON.stringify(row),
478
- });
479
- data = await response.json();
480
- } catch (e) {
481
- statusMessage.remove("<br><span>Inferring space...</span>");
482
- statusMessage.append(`<br><span style="color: red;">Error: Failed to infer space</span>`);
483
- return null;
484
- }
485
- statusMessage.remove("<br><span>Inferring space...</span>");
486
- if (data.error || !data.space) {
487
- if (data.error) {
488
- statusMessage.append(`<br><span style="color: red;">Error: ${data.error}</span>`);
489
- } else if (data.message) {
490
- statusMessage.append(`<br><span>${data.message}</span>`);
491
- } else {
492
- statusMessage.append(`<br><span style="color: red;">Error: Failed to infer space</span>`);
493
- }
494
- return null;
495
- }
496
- statusMessage.append(`<br><span style="color: green;">Inferred space: ${data.space}</span>`);
497
- return data.space;
498
- };
499
-
500
- const inferLicense = async (row: Row) => {
501
- statusMessage.append(`<br><span>Inferring license...</span>`);
502
- let data;
503
- try {
504
- const response = await fetch("/api/request", {
505
- method: "POST",
506
- headers: {
507
- endpoint: "infer-license",
508
- "Content-Type": "application/json",
509
- },
510
- body: JSON.stringify(row),
511
- });
512
- data = await response.json();
513
- } catch (e) {
514
- statusMessage.remove("<br><span>Inferring license...</span>");
515
- statusMessage.append(`<br><span style="color: red;">Error: Failed to infer license</span>`);
516
- return null;
517
- }
518
- statusMessage.remove("<br><span>Inferring license...</span>");
519
- if (data.error || !data.license) {
520
- if (data.error) {
521
- statusMessage.append(`<br><span style="color: red;">Error: ${data.error}</span>`);
522
- } else if (data.message) {
523
- statusMessage.append(`<br><span>${data.message}</span>`);
524
- } else {
525
- statusMessage.append(`<br><span style="color: red;">Error: Failed to infer license</span>`);
526
- }
527
- return null;
528
- }
529
- statusMessage.append(`<br><span style="color: green;">Inferred license: ${data.license}</span>`);
530
- return data.license;
531
- };
 
16
  return null;
17
  }
18
  };