upload download model from gui

This commit is contained in:
David Brazda
2023-12-06 15:23:05 +01:00
parent 01ff23907f
commit 5a5e94eeb5
4 changed files with 93 additions and 4 deletions

View File

@ -13,7 +13,7 @@ $(document).ready(function() {
} else {
const models = response.models;
models.forEach(function(model) {
$('#model-list').append('<p>' + model + '</p>');
$('#model-list').append('<p>' + model + ' <span class="delete-model" data-model="' + model + '">x</span></p>');
});
}
},
@ -23,6 +23,43 @@ $(document).ready(function() {
});
}
function deleteModel(modelName) {
$.ajax({
url: '/model/delete-model/' + modelName,
type: 'DELETE',
beforeSend: function (xhr) {
xhr.setRequestHeader('X-API-Key',
API_KEY); },
success: function(response) {
fetchModels(); // Refresh the list after deletion
},
error: function(xhr, status, error) {
alert('Error deleting model: ' + error);
}
});
}
function uploadModel(formData) {
$.ajax({
url: '/model/upload-model',
type: 'POST',
beforeSend: function (xhr) {
xhr.setRequestHeader('X-API-Key',
API_KEY); },
data: formData,
processData: false,
contentType: false,
success: function(response) {
fetchModels(); // Refresh the list after uploading
alert('Model uploaded successfully');
},
error: function(xhr, status, error) {
alert('Error uploading model: ' + error);
}
});
}
// Fetch models on page load
fetchModels();
@ -30,4 +67,24 @@ $(document).ready(function() {
$('#ml-refresh-button').click(function() {
fetchModels();
});
$('#model-list').on('click', '.delete-model', function() {
const modelName = $(this).data('model');
if (confirm('Are you sure you want to delete ' + modelName + '?')) {
deleteModel(modelName);
}
});
$('#upload-form').submit(function(e) {
e.preventDefault();
var formData = new FormData(this);
if (!$('#model-file')[0].files[0]) {
console.log("prazdne")
alert("No file selected.")
return
}
formData.append('file', $('#model-file')[0].files[0]); // Make sure 'file' matches the FastAPI parameter
uploadModel(formData);
});
});