diff --git a/v2realbot/main.py b/v2realbot/main.py index c12bc3c..ac669e2 100644 --- a/v2realbot/main.py +++ b/v2realbot/main.py @@ -833,6 +833,14 @@ def delete_model(model_name: str): else: 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 def insert_queue2db(): print("starting insert_queue2db thread") diff --git a/v2realbot/static/index.html b/v2realbot/static/index.html index 7158058..f2f03e8 100644 --- a/v2realbot/static/index.html +++ b/v2realbot/static/index.html @@ -793,7 +793,7 @@
- diff --git a/v2realbot/static/js/ml.js b/v2realbot/static/js/ml.js index 5c31a38..fa756e9 100644 --- a/v2realbot/static/js/ml.js +++ b/v2realbot/static/js/ml.js @@ -13,7 +13,13 @@ $(document).ready(function() { } else { const models = response.models; models.forEach(function(model) { - $('#model-list').append('' + model + ' x
'); + $('#model-list').append(` +${model} + [↓] + [x] +
+ `); + }); } }, @@ -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); + }); + }); diff --git a/v2realbot/static/main.css b/v2realbot/static/main.css index c81fb2f..7305161 100644 --- a/v2realbot/static/main.css +++ b/v2realbot/static/main.css @@ -49,17 +49,24 @@ } .scrollable-div { - width: 229px; + width: 262px; height: 143px; overflow-y: auto; border: 1px solid #585858; padding: 10px; } -.delete-model { - color: red; +/* ... existing CSS ... */ +.download-model, .delete-model { 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 {