-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
147 lines (111 loc) · 3.08 KB
/
index.js
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
import axios from "axios";
import express from "express";
import request from "request";
import fs from "fs";
import FormData from "form-data";
import multer from "multer"
import { dirname } from "path";
import { fileURLToPath } from "url";
const __dirname = dirname(fileURLToPath(import.meta.url));
const app=express();
const port=3000;
app.get('/',(req,res)=>{
res.render('index.ejs');
})
let data = new FormData();
// app.use(bodyParser.urlencoded({extended:true}));
// app.use(bodyParser.json());
app.use(express.json());
app.set('view engine', 'ejs');
// app.set("views", path.resolve("/views"));
app.use('/public', express.static('public'));
let code;
app.get('/check',(req,res)=>{
res.render('checkyourburn.ejs');
})
app.get('/thermal',(req,res)=>{
res.render('thermal.ejs');
})
app.get('/chemical',(req,res)=>{
res.render('chemical.ejs');
})
app.get('/radiation',(req,res)=>{
res.render('radiation.ejs');
})
app.get('/electric',(req,res)=>{
res.render('electric.ejs');
})
app.get('/features.ejs',(req,res)=>[
res.render('features')
])
app.get('/contact.ejs',(req,res)=>[
res.render('contact')
])
app.get('/aboutai.ejs',(req,res)=>[
res.render('aboutai')
])
app.get('/cl',(req,res)=>{
res.render('camera.ejs')
})
app.post('/done',(req,res)=>{
var data=req.body.FirstName;
console.log(data);
res.render('contact.ejs',{ });
})
let config = {
method: 'post',
maxBodyLength: Infinity,
url: 'http://13.48.136.54:8000/api/api-code/',
headers: {
'Authorization': 'Bearer e4a19872-caf9-448f-ad3d-17f26e5d32dd',
...data.getHeaders()
},
data : data
};
axios.post('http://13.48.136.54:8000/api/api-code/',data,config)
.then((response) => {
console.log(JSON.stringify(response.data));
code=JSON.stringify(response.data);
})
.catch((error) => {
console.log(error);
});
console.log(code);
const storage = multer.diskStorage({
destination: function (req, file, cb) {
return cb(null, "D:/start/uploads")
},
filename: function (req, file, cb) {
return cb(null, `${Date.now()}-${file.originalname}`)
}
})
const upload = multer({ storage })
app.post('/stats', upload.single('uploaded_file'), async(req,res,next)=>{
console.log(req.body.newItem);
const filePath = { "fname": req.file.path};
console.log(filePath);
let data = new FormData();
data.append('file', fs.createReadStream((req.file.path)));
console.log((req.file.path));
let config = {
method: 'post',
maxBodyLength: Infinity,
url: `http://127.0.0.1:8000/predict/?name=${req.body.newItem}`,
headers: {
...data.getHeaders()
},
data : data
};
axios.request(config)
.then((response) => {
console.log((response.data));
console.log(res.body);
res.render('prediction.ejs',{ data:response.data});;
})
.catch((error) => {
console.log(error);
});
});
app.listen(port,()=>{
console.log(`server is running at ${port} `)
})