|
@@ -0,0 +1,63 @@
|
|
|
|
+package org.example.car.controller;
|
|
|
|
+
|
|
|
|
+import org.example.car.model.Judge;
|
|
|
|
+import org.example.car.utils.FileUtil;
|
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
+
|
|
|
|
+import java.io.IOException;
|
|
|
|
+import java.nio.file.Files;
|
|
|
|
+import java.nio.file.Path;
|
|
|
|
+import java.nio.file.Paths;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
+
|
|
|
|
+@ResponseBody
|
|
|
|
+@RequestMapping("/tool")
|
|
|
|
+@Controller
|
|
|
|
+public class Tool {
|
|
|
|
+
|
|
|
|
+ @PostMapping("/call")
|
|
|
|
+ public Judge callTools(String modelName, String uid) {
|
|
|
|
+ Judge res = new Judge();
|
|
|
|
+ List<String> models = getModels();
|
|
|
|
+ if(modelName == null || !models.contains(modelName)){
|
|
|
|
+ res.setAccuracy(0.0);
|
|
|
|
+ res.setLosses(0.0);
|
|
|
|
+ res.setMemoryInfoList(0.0);
|
|
|
|
+ return res;
|
|
|
|
+ }
|
|
|
|
+ String command = "python --input-model-dir " + "models/" + modelName
|
|
|
|
+ + "--outout-dir" + "output-dir"
|
|
|
|
+ + " --output-timestamp" + uid;
|
|
|
|
+ try{
|
|
|
|
+ Process process = Runtime.getRuntime().exec(command);
|
|
|
|
+ }catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ res.setAccuracy(0.0);
|
|
|
|
+ res.setLosses(0.0);
|
|
|
|
+ res.setMemoryInfoList(0.0);
|
|
|
|
+ return res;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return res;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @GetMapping("/getModels")
|
|
|
|
+ public List<String> getModels() {
|
|
|
|
+ String modelsDirectory = "models";
|
|
|
|
+ try{
|
|
|
|
+ return FileUtil.listModels(modelsDirectory);
|
|
|
|
+ }catch (IOException e){
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ return new ArrayList<>();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|