Spaces:
Running
Running
Ron Au
commited on
Commit
·
0c0e375
1
Parent(s):
0a51235
refactor(basePath): Improve utility function
Browse files- static/js/network.js +11 -6
static/js/network.js
CHANGED
|
@@ -1,26 +1,31 @@
|
|
| 1 |
-
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
};
|
| 4 |
|
| 5 |
const generateDetails = async () => {
|
| 6 |
-
const details = await fetch(
|
| 7 |
return await details.json();
|
| 8 |
};
|
| 9 |
|
| 10 |
const createTask = async (prompt) => {
|
| 11 |
-
const taskResponse = await fetch(
|
| 12 |
const task = await taskResponse.json();
|
| 13 |
|
| 14 |
return task;
|
| 15 |
};
|
| 16 |
|
| 17 |
const queueTask = async (task_id) => {
|
| 18 |
-
const queueResponse = await fetch(
|
| 19 |
return queueResponse.json();
|
| 20 |
};
|
| 21 |
|
| 22 |
const pollTask = async (task) => {
|
| 23 |
-
const taskResponse = await fetch(
|
| 24 |
|
| 25 |
return await taskResponse.json();
|
| 26 |
};
|
|
|
|
| 1 |
+
/**
|
| 2 |
+
* Reconcile paths for hf.space resources fetched from hf.co iframe
|
| 3 |
+
*/
|
| 4 |
+
|
| 5 |
+
const pathFor = (path) => {
|
| 6 |
+
const basePath = document.location.origin + document.location.pathname;
|
| 7 |
+
return new URL(path, basePath).href;
|
| 8 |
};
|
| 9 |
|
| 10 |
const generateDetails = async () => {
|
| 11 |
+
const details = await fetch(pathFor('details'));
|
| 12 |
return await details.json();
|
| 13 |
};
|
| 14 |
|
| 15 |
const createTask = async (prompt) => {
|
| 16 |
+
const taskResponse = await fetch(pathFor(`task/create?prompt=${prompt}`));
|
| 17 |
const task = await taskResponse.json();
|
| 18 |
|
| 19 |
return task;
|
| 20 |
};
|
| 21 |
|
| 22 |
const queueTask = async (task_id) => {
|
| 23 |
+
const queueResponse = await fetch(pathFor(`task/queue?task_id=${task_id}`));
|
| 24 |
return queueResponse.json();
|
| 25 |
};
|
| 26 |
|
| 27 |
const pollTask = async (task) => {
|
| 28 |
+
const taskResponse = await fetch(pathFor(`task/poll?task_id=${task.task_id}`));
|
| 29 |
|
| 30 |
return await taskResponse.json();
|
| 31 |
};
|