-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_e.js
More file actions
84 lines (77 loc) · 3.11 KB
/
Copy pathmain_e.js
File metadata and controls
84 lines (77 loc) · 3.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// const { exec } = require("child_process");
// const express = require("express");
// const app = express();
// const path = require("path");
// const publicPath = path.join(__dirname, "public");
// const multer = require("multer");
// const uuid4 = require("uuid4");
// const fs = require("fs");
// const os = require("os");
// //지금 pod의 실행을 담당하는 worker node의 hostname을 참조
// const nodeName = process.env.NODE_NAME;
// app.use(express.static(publicPath));
// const upload = multer({
// storage: multer.diskStorage({
// filename(req, file, done) {
// const randomID = uuid4();
// const ext = path.extname(file.originalname);
// const filename = randomID + ext;
// done(null, filename);
// },
// destination(req, file, done) {
// done(null, path.join(__dirname, "files"));
// },
// }),
// });
// const uploadMiddleware = upload.array("myFiles");
// app.post("/upload", uploadMiddleware, (req, res) => {
// const uploadedFilePath = req.files[0].path;
// const homeDir = os.homedir();
// const pycoralPath = path.join(homeDir, "coral");
// const nd1Path = path.join(homeDir, "nd1");
// fs.access(pycoralPath, fs.constants.F_OK, (err) => {
// if (!err) {
// // ~/pycoral 디렉토리가 존재하는 경우
// console.log('coral exist!');
// const pythonCommand = `python3 ~/coral/pycoral/examples/classify_image.py \
// --model ~/coral/pycoral/test_data/mobilenet_v2_1.0_224_inat_bird_quant_edgetpu.tflite \
// --labels ~/coral/pycoral/test_data/inat_bird_labels.txt \
// --input ${uploadedFilePath}`;
// executePythonCommand(pythonCommand);
// } else {
// // ~/pycoral 디렉토리가 없는 경우, ~/nd1 디렉토리를 확인
// fs.access(nd1Path, fs.constants.F_OK, (err) => {
// if (!err) {
// console.log('coral is unexist but nd1 is exist!');
// // ~/nd1 디렉토리가 존재하는 경우
// const pythonCommand = `python3 ~/nd1/coral/pycoral/examples/ci4.py \
// --model ~/nd1/coral/pycoral/test_data/mobilenet_v2_1.0_224_inat_bird_quant.tflite \
// --labels ~/nd1/coral/pycoral/test_data/inat_bird_labels.txt \
// --input ${uploadedFilePath}`;
// executePythonCommand(pythonCommand);
// } else {
// console.log('both unexist!')
// // 둘 다 존재하지 않는 경우
// return res.status(500).send("Error: Neither pycoral nor nd1 directories exist.");
// }
// });
// }
// });
// function executePythonCommand(pythonCommand) {
// exec(pythonCommand, (error, stdout, stderr) => {
// if (error) {
// console.error(`exec error: ${error}`);
// return res.status(500).send(`Error: ${error.message}`);
// }
// if (stderr) {
// console.error(`stderr: ${stderr}`);
// return res.status(500).send(`Error: ${stderr}`);
// }
// console.log(`stdout: ${stdout}`);
// res.status(200).send(stdout);
// });
// }
// });
// app.listen(12345, () => {
// console.log("Server is running at 12345");
// });