download model

This commit is contained in:
David Brazda
2023-12-06 19:47:03 +01:00
parent 5a5e94eeb5
commit 8abebcc910
4 changed files with 59 additions and 6 deletions

View File

@ -13,7 +13,13 @@ $(document).ready(function() {
} else {
const models = response.models;
models.forEach(function(model) {
$('#model-list').append('<p>' + model + ' <span class="delete-model" data-model="' + model + '">x</span></p>');
$('#model-list').append(`
<p>${model}
<span class="download-model" data-model="${model}">[↓]</span>
<span class="delete-model" data-model="${model}">[x]</span>
</p>
`);
});
}
},
@ -59,6 +65,32 @@ $(document).ready(function() {
});
}
function downloadModel(modelName) {
$.ajax({
url: '/model/download-model/' + modelName,
type: 'GET',
beforeSend: function (xhr) {
xhr.setRequestHeader('X-API-Key', API_KEY);
},
success: function(data, status, xhr) {
// Get a URL for the blob to download
var blob = new Blob([data], { type: xhr.getResponseHeader('Content-Type') });
var downloadUrl = URL.createObjectURL(blob);
var a = document.createElement('a');
a.href = downloadUrl;
a.download = modelName;
document.body.appendChild(a);
a.click();
// Clean up
window.URL.revokeObjectURL(downloadUrl);
a.remove();
},
error: function(xhr, status, error) {
alert('Error downloading model: ' + error);
}
});
}
// Fetch models on page load
fetchModels();
@ -87,4 +119,10 @@ $(document).ready(function() {
uploadModel(formData);
});
//Handler to download the model
$('#model-list').on('click', '.download-model', function() {
const modelName = $(this).data('model');
downloadModel(modelName);
});
});