Skip to content

Commit

Permalink
DL model files from bucket
Browse files Browse the repository at this point in the history
  • Loading branch information
sevagh committed Feb 23, 2024
1 parent 3397ce7 commit d373f36
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
Binary file removed docs/assets/models/ggml-model-htdemucs-4s-f16.bin
Binary file not shown.
Binary file removed docs/assets/models/ggml-model-htdemucs-6s-f16.bin
Binary file not shown.
5 changes: 4 additions & 1 deletion docs/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,9 @@ function initWorkers() {
}
};

// cloudflare R2 bucket
const dl_prefix = "https://bucket.freemusicdemixer.com";

function fetchAndCacheFiles(model) {
let modelFiles = [];
if (model === 'demucs-4s') {
Expand All @@ -308,7 +311,7 @@ function fetchAndCacheFiles(model) {

// prepend raw gh url to all modelFiles
modelFiles = modelFiles.map(file =>
`assets/models/${file}`
`${dl_prefix}/${file}`
)

// Map each file to a fetch request and then process the response
Expand Down
13 changes: 7 additions & 6 deletions docs/service-worker.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const CACHE_NAME = "v20240213";
const CACHE_NAME = "v20240223";
const RESOURCES_TO_PRELOAD = [
"assets/models/ggml-model-htdemucs-4s-f16.bin",
"assets/models/ggml-model-htdemucs-6s-f16.bin"
"https://bucket.freemusicdemixer.com/ggml-model-htdemucs-4s-f16.bin",
"https://bucket.freemusicdemixer.com/ggml-model-htdemucs-6s-f16.bin",
];

// Pre-cache resources
Expand Down Expand Up @@ -34,8 +34,9 @@ self.addEventListener("activate", (event) => {
});

self.addEventListener("fetch", (event) => {
// Check if the request is for a .bin file
if (event.request.url.endsWith('.bin')) {
// Check if the request is for a .bin file from the external resource
if (event.request.url.startsWith("https://bucket.freemusicdemixer.com/") &&
event.request.url.endsWith('.bin')) {
event.respondWith(
caches.open(CACHE_NAME).then(cache => {
return cache.match(event.request).then(response => {
Expand All @@ -52,7 +53,7 @@ self.addEventListener("fetch", (event) => {
})
);
} else {
// For non-.bin files, just fetch from the network
// For non-.bin files or requests not to the specific domain, just fetch from the network
event.respondWith(fetch(event.request));
}
});

0 comments on commit d373f36

Please sign in to comment.