dylanebert HF staff commited on
Commit
7d88b7e
·
1 Parent(s): 995bc63

route through backend

Browse files
.gitmodules DELETED
@@ -1,4 +0,0 @@
1
- [submodule "viewer/svelte-table"]
2
- path = viewer/svelte-table
3
- url = https://github.com/dylanebert/svelte-table.git
4
- branch = master
 
 
 
 
 
viewer/package-lock.json CHANGED
The diff for this file is too large to render. See raw diff
 
viewer/package.json CHANGED
@@ -11,6 +11,7 @@
11
  "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
12
  },
13
  "devDependencies": {
 
14
  "@sveltejs/adapter-auto": "^3.0.0",
15
  "@sveltejs/adapter-node": "^4.0.0",
16
  "@sveltejs/kit": "^2.0.0",
@@ -19,12 +20,11 @@
19
  "svelte-check": "^3.6.0",
20
  "tslib": "^2.4.1",
21
  "typescript": "^5.0.0",
22
- "vite": "^5.0.12",
23
- "@rollup/rollup-linux-x64-gnu": "^4.9.6"
24
  },
25
  "type": "module",
26
  "dependencies": {
27
  "esbuild": "^0.19.12",
28
- "svelte-table": "file:./svelte-table"
29
  }
30
  }
 
11
  "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch"
12
  },
13
  "devDependencies": {
14
+ "@rollup/rollup-linux-x64-gnu": "^4.9.6",
15
  "@sveltejs/adapter-auto": "^3.0.0",
16
  "@sveltejs/adapter-node": "^4.0.0",
17
  "@sveltejs/kit": "^2.0.0",
 
20
  "svelte-check": "^3.6.0",
21
  "tslib": "^2.4.1",
22
  "typescript": "^5.0.0",
23
+ "vite": "^5.0.12"
 
24
  },
25
  "type": "module",
26
  "dependencies": {
27
  "esbuild": "^0.19.12",
28
+ "svelte-table": "^0.6.3"
29
  }
30
  }
viewer/src/routes/+page.svelte CHANGED
@@ -373,11 +373,7 @@
373
  let isModalOpen = false;
374
  </script>
375
 
376
- {#if !import.meta.env.VITE_HF_TOKEN}
377
- <div style="text-align: center; margin-top: 1rem;">
378
- <p>Missing VITE_HF_TOKEN environment variable</p>
379
- </div>
380
- {:else if fetching}
381
  <div style="text-align: center; margin-top: 1rem;">
382
  <p>{@html $statusMessage}</p>
383
  </div>
 
373
  let isModalOpen = false;
374
  </script>
375
 
376
+ {#if fetching}
 
 
 
 
377
  <div style="text-align: center; margin-top: 1rem;">
378
  <p>{@html $statusMessage}</p>
379
  </div>
viewer/src/routes/api/fetchRows/+server.ts ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export const GET = async () => {
2
+ const response = await fetch("https://dylanebert-research-tracker-backend.hf.space/data", {
3
+ method: "GET",
4
+ headers: {
5
+ Authorization: "Bearer " + import.meta.env.VITE_HF_TOKEN,
6
+ "Cache-Control": "no-cache",
7
+ },
8
+ });
9
+ const rows = await response.json();
10
+ return new Response(JSON.stringify(rows));
11
+ };
viewer/src/routes/api/request/+server.ts ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
@@ -1,19 +1,10 @@
1
  import Row from "./Row";
2
  import { statusMessage } from "./store";
3
 
4
- const baseURL = "https://dylanebert-research-tracker-backend.hf.space";
5
- // const baseURL = "http://localhost:8000";
6
-
7
  export const fetchRows = async (): Promise<Row[] | null> => {
8
  statusMessage.set(`<span>Fetching data from https://dylanebert-research-tracker-backend.hf.space/data</span>`);
9
  try {
10
- const response = await fetch(baseURL + "/data", {
11
- method: "GET",
12
- headers: {
13
- Authorization: "Bearer " + import.meta.env.VITE_HF_TOKEN,
14
- "Cache-Control": "no-cache",
15
- },
16
- });
17
  const rows = await response.json();
18
  statusMessage.reset();
19
  return rows;
@@ -54,11 +45,11 @@ export const addEntry = async (selection: Record<string | number, any>): Promise
54
  if (!row) {
55
  return null;
56
  }
57
- const response = await fetch(baseURL + "/add-entry", {
58
  method: "POST",
59
  headers: {
60
  "Content-Type": "application/json",
61
- Authorization: "Bearer " + import.meta.env.VITE_HF_TOKEN,
62
  },
63
  body: JSON.stringify(row),
64
  });
@@ -82,11 +73,11 @@ export const editEntry = async (row: Row): Promise<Row | null> => {
82
  ? row.Authors
83
  : (row.Authors as any).split(",").map((author: string) => author.trim());
84
  row.Tags = Array.isArray(row.Tags) ? row.Tags : (row.Tags as any).split(",").map((tag: string) => tag.trim());
85
- const response = await fetch(baseURL + "/edit-entry", {
86
  method: "POST",
87
  headers: {
88
  "Content-Type": "application/json",
89
- Authorization: "Bearer " + import.meta.env.VITE_HF_TOKEN,
90
  },
91
  body: JSON.stringify(row),
92
  });
@@ -109,11 +100,11 @@ export const deleteEntry = async (row: Row): Promise<Row | null> => {
109
  ? row.Authors
110
  : (row.Authors as any).split(",").map((author: string) => author.trim());
111
  row.Tags = Array.isArray(row.Tags) ? row.Tags : (row.Tags as any).split(",").map((tag: string) => tag.trim());
112
- const response = await fetch(baseURL + "/delete-entry", {
113
  method: "POST",
114
  headers: {
115
  "Content-Type": "application/json",
116
- Authorization: "Bearer " + import.meta.env.VITE_HF_TOKEN,
117
  },
118
  body: JSON.stringify(row),
119
  });
@@ -181,11 +172,11 @@ export const inferFields = async (row: Row): Promise<Row | null> => {
181
  const inferFieldType = async (row: Row, value: string): Promise<string | null> => {
182
  let data;
183
  try {
184
- const response = await fetch(baseURL + "/infer-field", {
185
  method: "POST",
186
  headers: {
187
  "Content-Type": "application/json",
188
- Authorization: "Bearer " + import.meta.env.VITE_HF_TOKEN,
189
  },
190
  body: JSON.stringify({ value }),
191
  });
@@ -208,11 +199,11 @@ const inferPaper = async (row: Row) => {
208
  statusMessage.append(`<br><span>Inferring paper...</span>`);
209
  let data;
210
  try {
211
- const response = await fetch(baseURL + "/infer-paper", {
212
  method: "POST",
213
  headers: {
214
  "Content-Type": "application/json",
215
- Authorization: "Bearer " + import.meta.env.VITE_HF_TOKEN,
216
  },
217
  body: JSON.stringify(row),
218
  });
@@ -242,11 +233,11 @@ const inferCode = async (row: Row) => {
242
  statusMessage.append(`<br><span>Inferring code...</span>`);
243
  let data;
244
  try {
245
- const response = await fetch(baseURL + "/infer-code", {
246
  method: "POST",
247
  headers: {
 
248
  "Content-Type": "application/json",
249
- Authorization: "Bearer " + import.meta.env.VITE_HF_TOKEN,
250
  },
251
  body: JSON.stringify(row),
252
  });
@@ -276,11 +267,11 @@ const inferName = async (row: Row) => {
276
  statusMessage.append(`<br><span>Inferring name...</span>`);
277
  let data;
278
  try {
279
- const response = await fetch(baseURL + "/infer-name", {
280
  method: "POST",
281
  headers: {
 
282
  "Content-Type": "application/json",
283
- Authorization: "Bearer " + import.meta.env.VITE_HF_TOKEN,
284
  },
285
  body: JSON.stringify(row),
286
  });
@@ -309,11 +300,11 @@ const inferAuthors = async (row: Row) => {
309
  statusMessage.append(`<br><span>Inferring authors...</span>`);
310
  let data;
311
  try {
312
- const response = await fetch(baseURL + "/infer-authors", {
313
  method: "POST",
314
  headers: {
 
315
  "Content-Type": "application/json",
316
- Authorization: "Bearer " + import.meta.env.VITE_HF_TOKEN,
317
  },
318
  body: JSON.stringify(row),
319
  });
@@ -342,11 +333,11 @@ const inferOrgs = async (row: Row) => {
342
  statusMessage.append(`<br><span>Inferring orgs...</span>`);
343
  let data;
344
  try {
345
- const response = await fetch(baseURL + "/infer-orgs", {
346
  method: "POST",
347
  headers: {
 
348
  "Content-Type": "application/json",
349
- Authorization: "Bearer " + import.meta.env.VITE_HF_TOKEN,
350
  },
351
  body: JSON.stringify(row),
352
  });
@@ -375,11 +366,11 @@ const inferDate = async (row: Row) => {
375
  statusMessage.append(`<br><span>Inferring date...</span>`);
376
  let data;
377
  try {
378
- const response = await fetch(baseURL + "/infer-date", {
379
  method: "POST",
380
  headers: {
 
381
  "Content-Type": "application/json",
382
- Authorization: "Bearer " + import.meta.env.VITE_HF_TOKEN,
383
  },
384
  body: JSON.stringify(row),
385
  });
@@ -408,11 +399,11 @@ const inferModel = async (row: Row) => {
408
  statusMessage.append(`<br><span>Inferring model...</span>`);
409
  let data;
410
  try {
411
- const response = await fetch(baseURL + "/infer-model", {
412
  method: "POST",
413
  headers: {
 
414
  "Content-Type": "application/json",
415
- Authorization: "Bearer " + import.meta.env.VITE_HF_TOKEN,
416
  },
417
  body: JSON.stringify(row),
418
  });
@@ -441,11 +432,11 @@ const inferDataset = async (row: Row) => {
441
  statusMessage.append(`<br><span>Inferring dataset...</span>`);
442
  let data;
443
  try {
444
- const response = await fetch(baseURL + "/infer-dataset", {
445
  method: "POST",
446
  headers: {
 
447
  "Content-Type": "application/json",
448
- Authorization: "Bearer " + import.meta.env.VITE_HF_TOKEN,
449
  },
450
  body: JSON.stringify(row),
451
  });
@@ -474,11 +465,11 @@ const inferSpace = async (row: Row) => {
474
  statusMessage.append(`<br><span>Inferring space...</span>`);
475
  let data;
476
  try {
477
- const response = await fetch(baseURL + "/infer-space", {
478
  method: "POST",
479
  headers: {
 
480
  "Content-Type": "application/json",
481
- Authorization: "Bearer " + import.meta.env.VITE_HF_TOKEN,
482
  },
483
  body: JSON.stringify(row),
484
  });
@@ -507,11 +498,11 @@ const inferLicense = async (row: Row) => {
507
  statusMessage.append(`<br><span>Inferring license...</span>`);
508
  let data;
509
  try {
510
- const response = await fetch(baseURL + "/infer-license", {
511
  method: "POST",
512
  headers: {
 
513
  "Content-Type": "application/json",
514
- Authorization: "Bearer " + import.meta.env.VITE_HF_TOKEN,
515
  },
516
  body: JSON.stringify(row),
517
  });
 
1
  import Row from "./Row";
2
  import { statusMessage } from "./store";
3
 
 
 
 
4
  export const fetchRows = async (): Promise<Row[] | null> => {
5
  statusMessage.set(`<span>Fetching data from https://dylanebert-research-tracker-backend.hf.space/data</span>`);
6
  try {
7
+ const response = await fetch("/api/fetchRows");
 
 
 
 
 
 
8
  const rows = await response.json();
9
  statusMessage.reset();
10
  return rows;
 
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
  });
 
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
  });
 
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
  });
 
172
  const inferFieldType = async (row: Row, value: string): Promise<string | null> => {
173
  let data;
174
  try {
175
+ const response = await fetch("/api/request", {
176
  method: "POST",
177
  headers: {
178
  "Content-Type": "application/json",
179
+ endpoint: "infer-field",
180
  },
181
  body: JSON.stringify({ value }),
182
  });
 
199
  statusMessage.append(`<br><span>Inferring paper...</span>`);
200
  let data;
201
  try {
202
+ const response = await fetch("/api/request", {
203
  method: "POST",
204
  headers: {
205
  "Content-Type": "application/json",
206
+ endpoint: "infer-paper",
207
  },
208
  body: JSON.stringify(row),
209
  });
 
233
  statusMessage.append(`<br><span>Inferring code...</span>`);
234
  let data;
235
  try {
236
+ const response = await fetch("/api/request", {
237
  method: "POST",
238
  headers: {
239
+ endpoint: "infer-code",
240
  "Content-Type": "application/json",
 
241
  },
242
  body: JSON.stringify(row),
243
  });
 
267
  statusMessage.append(`<br><span>Inferring name...</span>`);
268
  let data;
269
  try {
270
+ const response = await fetch("/api/request", {
271
  method: "POST",
272
  headers: {
273
+ endpoint: "infer-name",
274
  "Content-Type": "application/json",
 
275
  },
276
  body: JSON.stringify(row),
277
  });
 
300
  statusMessage.append(`<br><span>Inferring authors...</span>`);
301
  let data;
302
  try {
303
+ const response = await fetch("/api/request", {
304
  method: "POST",
305
  headers: {
306
+ endpoint: "infer-authors",
307
  "Content-Type": "application/json",
 
308
  },
309
  body: JSON.stringify(row),
310
  });
 
333
  statusMessage.append(`<br><span>Inferring orgs...</span>`);
334
  let data;
335
  try {
336
+ const response = await fetch("/api/request", {
337
  method: "POST",
338
  headers: {
339
+ endpoint: "infer-orgs",
340
  "Content-Type": "application/json",
 
341
  },
342
  body: JSON.stringify(row),
343
  });
 
366
  statusMessage.append(`<br><span>Inferring date...</span>`);
367
  let data;
368
  try {
369
+ const response = await fetch("/api/request", {
370
  method: "POST",
371
  headers: {
372
+ endpoint: "infer-date",
373
  "Content-Type": "application/json",
 
374
  },
375
  body: JSON.stringify(row),
376
  });
 
399
  statusMessage.append(`<br><span>Inferring model...</span>`);
400
  let data;
401
  try {
402
+ const response = await fetch("/api/request", {
403
  method: "POST",
404
  headers: {
405
+ endpoint: "infer-model",
406
  "Content-Type": "application/json",
 
407
  },
408
  body: JSON.stringify(row),
409
  });
 
432
  statusMessage.append(`<br><span>Inferring dataset...</span>`);
433
  let data;
434
  try {
435
+ const response = await fetch("/api/request", {
436
  method: "POST",
437
  headers: {
438
+ endpoint: "infer-dataset",
439
  "Content-Type": "application/json",
 
440
  },
441
  body: JSON.stringify(row),
442
  });
 
465
  statusMessage.append(`<br><span>Inferring space...</span>`);
466
  let data;
467
  try {
468
+ const response = await fetch("/api/request", {
469
  method: "POST",
470
  headers: {
471
+ endpoint: "infer-space",
472
  "Content-Type": "application/json",
 
473
  },
474
  body: JSON.stringify(row),
475
  });
 
498
  statusMessage.append(`<br><span>Inferring license...</span>`);
499
  let data;
500
  try {
501
+ const response = await fetch("/api/request", {
502
  method: "POST",
503
  headers: {
504
+ endpoint: "infer-license",
505
  "Content-Type": "application/json",
 
506
  },
507
  body: JSON.stringify(row),
508
  });
viewer/svelte-table DELETED
@@ -1 +0,0 @@
1
- Subproject commit 0b3742da9031342a5ce9af34c673be8f48c1eefb