download model
This commit is contained in:
@ -833,6 +833,14 @@ def delete_model(model_name: str):
|
|||||||
else:
|
else:
|
||||||
raise HTTPException(status_code=404, detail="Model not found.")
|
raise HTTPException(status_code=404, detail="Model not found.")
|
||||||
|
|
||||||
|
@app.get("/model/download-model/{model_name}", dependencies=[Depends(api_key_auth)])
|
||||||
|
def download_model(model_name: str):
|
||||||
|
model_path = os.path.join(MODEL_DIR, model_name)
|
||||||
|
if os.path.exists(model_path):
|
||||||
|
return FileResponse(path=model_path, filename=model_name, media_type='application/octet-stream')
|
||||||
|
else:
|
||||||
|
raise HTTPException(status_code=404, detail="Model not found.")
|
||||||
|
|
||||||
# Thread function to insert data from the queue into the database
|
# Thread function to insert data from the queue into the database
|
||||||
def insert_queue2db():
|
def insert_queue2db():
|
||||||
print("starting insert_queue2db thread")
|
print("starting insert_queue2db thread")
|
||||||
|
|||||||
@ -793,7 +793,7 @@
|
|||||||
<button id="ml-refresh-button" class="btn btn-outline-success btn-sm">Refresh Models</button>
|
<button id="ml-refresh-button" class="btn btn-outline-success btn-sm">Refresh Models</button>
|
||||||
<div id="model-list" class="scrollable-div"></div>
|
<div id="model-list" class="scrollable-div"></div>
|
||||||
<!-- Upload Form -->
|
<!-- Upload Form -->
|
||||||
<form id="upload-form" enctype="multipart/form-data" style="width: 229px;">
|
<form id="upload-form" enctype="multipart/form-data" style="width: 262px;">
|
||||||
<input type="file" class="form-control form-control-sm" id="model-file" name="model-file">
|
<input type="file" class="form-control form-control-sm" id="model-file" name="model-file">
|
||||||
<button type="submit" class="btn btn-outline-success btn-sm">Upload Model</button>
|
<button type="submit" class="btn btn-outline-success btn-sm">Upload Model</button>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@ -13,7 +13,13 @@ $(document).ready(function() {
|
|||||||
} else {
|
} else {
|
||||||
const models = response.models;
|
const models = response.models;
|
||||||
models.forEach(function(model) {
|
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
|
// Fetch models on page load
|
||||||
fetchModels();
|
fetchModels();
|
||||||
@ -87,4 +119,10 @@ $(document).ready(function() {
|
|||||||
uploadModel(formData);
|
uploadModel(formData);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//Handler to download the model
|
||||||
|
$('#model-list').on('click', '.download-model', function() {
|
||||||
|
const modelName = $(this).data('model');
|
||||||
|
downloadModel(modelName);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@ -49,17 +49,24 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.scrollable-div {
|
.scrollable-div {
|
||||||
width: 229px;
|
width: 262px;
|
||||||
height: 143px;
|
height: 143px;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
border: 1px solid #585858;
|
border: 1px solid #585858;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.delete-model {
|
/* ... existing CSS ... */
|
||||||
color: red;
|
.download-model, .delete-model {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
margin-left: 10px;
|
padding: 0 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.download-model {
|
||||||
|
color: green; /* or use an actual icon */
|
||||||
|
}
|
||||||
|
.delete-model {
|
||||||
|
color: red; /* or use an actual icon */
|
||||||
}
|
}
|
||||||
|
|
||||||
.stat_div {
|
.stat_div {
|
||||||
|
|||||||
Reference in New Issue
Block a user