diff --git a/photon-core/src/main/java/org/photonvision/common/configuration/NeuralNetworkModelManager.java b/photon-core/src/main/java/org/photonvision/common/configuration/NeuralNetworkModelManager.java index 3ede4ba34b..f053910544 100644 --- a/photon-core/src/main/java/org/photonvision/common/configuration/NeuralNetworkModelManager.java +++ b/photon-core/src/main/java/org/photonvision/common/configuration/NeuralNetworkModelManager.java @@ -137,6 +137,11 @@ public HashMap> getModels() { return modelMap; } + public void rescanModels(File modelsDirectory) { + models = null; + discoverModels(modelsDirectory); + } + /** * Retrieves the model with the specified name, assuming it is available under a supported * backend. diff --git a/photon-server/src/main/java/org/photonvision/server/RequestHandler.java b/photon-server/src/main/java/org/photonvision/server/RequestHandler.java index ac92209a37..4871eeaaf5 100644 --- a/photon-server/src/main/java/org/photonvision/server/RequestHandler.java +++ b/photon-server/src/main/java/org/photonvision/server/RequestHandler.java @@ -585,15 +585,27 @@ public static void onImportObjectDetectionModelRequest(Context ctx) { logger.error("The uploaded object detection model files were not named correctly."); return; } - File tmpModel = Files.createTempFile(modelFile.filename(), null).toFile(); - File tmpLabels = Files.createTempFile(labelsFile.filename(), null).toFile(); - if (!NeuralNetworkModelManager.getInstance() - .addNewModel(tmpModel, tmpLabels, ConfigManager.getInstance().getModelsDirectory())) { - ctx.status(500).result("Error processing files: Check logs for more information"); - return; + // TODO move into neural network manager + + var modelPath = + Paths.get( + ConfigManager.getInstance().getModelsDirectory().toString(), modelFile.filename()); + var labelsPath = + Paths.get( + ConfigManager.getInstance().getModelsDirectory().toString(), labelsFile.filename()); + + try (FileOutputStream out = new FileOutputStream(modelPath.toFile())) { + modelFile.content().transferTo(out); } + try (FileOutputStream out = new FileOutputStream(labelsPath.toFile())) { + labelsFile.content().transferTo(out); + } + + NeuralNetworkModelManager.getInstance() + .rescanModels(ConfigManager.getInstance().getModelsDirectory()); + ctx.status(200).result("Successfully uploaded object detection model"); } catch (Exception e) { ctx.status(500).result("Error processing files: " + e.getMessage());