Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2023-029
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2023-029
2023-029
Commits
44218348
Commit
44218348
authored
Aug 29, 2023
by
janithgamage1.ed
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix:fix: update
desc: update project
parent
d073333a
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
281 additions
and
1 deletion
+281
-1
Project/Backend/Server_Node/controllers/marksCalculator.controller.js
...end/Server_Node/controllers/marksCalculator.controller.js
+32
-0
Project/Backend/Server_Node/package-lock.json
Project/Backend/Server_Node/package-lock.json
+140
-0
Project/Backend/Server_Node/package.json
Project/Backend/Server_Node/package.json
+1
-0
Project/Backend/Server_Node/prediction_config/C1T1/predict.py
...ect/Backend/Server_Node/prediction_config/C1T1/predict.py
+92
-0
Project/Backend/Server_Node/prediction_config/C1T1/trained_model_modified.pth
...er_Node/prediction_config/C1T1/trained_model_modified.pth
+0
-0
Project/Backend/Server_Node/routes/marksCalculator.routes.js
Project/Backend/Server_Node/routes/marksCalculator.routes.js
+13
-0
Project/Backend/Server_Node/server.js
Project/Backend/Server_Node/server.js
+3
-1
No files found.
Project/Backend/Server_Node/controllers/marksCalculator.controller.js
0 → 100644
View file @
44218348
import
{
exec
}
from
"
child_process
"
;
export
const
marksCalculator
=
async
(
req
,
res
)
=>
{
const
imageData
=
req
.
file
.
buffer
.
toString
(
'
base64
'
);
const
targetClass
=
req
.
body
.
class
;
try
{
// Run Python script to perform prediction
const
pythonProcess
=
exec
(
'
python prediction_config/C1T1/predict.py
'
,
(
error
,
stdout
,
stderr
)
=>
{
if
(
error
)
{
console
.
error
(
error
);
return
res
.
status
(
500
).
json
({
error
:
'
An error occurred
'
});
}
const
[
predictedClass
,
confidence
]
=
stdout
.
trim
().
split
(
'
,
'
);
res
.
status
(
200
).
json
({
code
:
"
01
"
,
result
:
{
predictedClass
,
confidence
:
parseFloat
(
confidence
).
toFixed
(
2
),
}
});
});
pythonProcess
.
stdin
.
write
(
`
${
imageData
}
\n
${
targetClass
}
`
);
pythonProcess
.
stdin
.
end
();
}
catch
(
error
)
{
res
.
status
(
500
).
json
({
code
:
"
00
"
,
message
:
"
Something went wrong
"
})
}
}
\ No newline at end of file
Project/Backend/Server_Node/package-lock.json
View file @
44218348
...
@@ -19,6 +19,7 @@
...
@@ -19,6 +19,7 @@
"multer"
:
"^1.4.5-lts.1"
,
"multer"
:
"^1.4.5-lts.1"
,
"nodemailer"
:
"^6.9.1"
,
"nodemailer"
:
"^6.9.1"
,
"nodemon"
:
"^2.0.22"
,
"nodemon"
:
"^2.0.22"
,
"torch"
:
"^0.2.7"
,
"uuid"
:
"^9.0.0"
"uuid"
:
"^9.0.0"
}
}
},
},
...
@@ -58,6 +59,22 @@
...
@@ -58,6 +59,22 @@
"node"
:
">= 0.6"
"node"
:
">= 0.6"
}
}
},
},
"node_modules/ansi-regex"
:
{
"version"
:
"2.1.1"
,
"resolved"
:
"https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz"
,
"integrity"
:
"sha512-TIGnTpdo+E3+pCyAluZvtED5p5wCqLdezCyhPZzKPcxvFplEt4i+W7OONCKgeZFT3+y5NZZfOOS/Bdcanm1MYA=="
,
"engines"
:
{
"node"
:
">=0.10.0"
}
},
"node_modules/ansi-styles"
:
{
"version"
:
"2.2.1"
,
"resolved"
:
"https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz"
,
"integrity"
:
"sha512-kmCevFghRiWM7HB5zTPULl4r9bVFSWjz62MhqizDGUrq2NWuNMQyuv4tHHoKJHs69M/MF64lEcHdYIocrdWQYA=="
,
"engines"
:
{
"node"
:
">=0.10.0"
}
},
"node_modules/anymatch"
:
{
"node_modules/anymatch"
:
{
"version"
:
"3.1.3"
,
"version"
:
"3.1.3"
,
"resolved"
:
"https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz"
,
"resolved"
:
"https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz"
,
...
@@ -190,6 +207,29 @@
...
@@ -190,6 +207,29 @@
"url"
:
"https://github.com/sponsors/ljharb"
"url"
:
"https://github.com/sponsors/ljharb"
}
}
},
},
"node_modules/chalk"
:
{
"version"
:
"1.1.3"
,
"resolved"
:
"https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz"
,
"integrity"
:
"sha512-U3lRVLMSlsCfjqYPbLyVv11M9CPW4I728d6TCKMAOJueEeB9/8o+eSsMnxPJD+Q+K909sdESg7C+tIkoH6on1A=="
,
"dependencies"
:
{
"ansi-styles"
:
"^2.2.1"
,
"escape-string-regexp"
:
"^1.0.2"
,
"has-ansi"
:
"^2.0.0"
,
"strip-ansi"
:
"^3.0.0"
,
"supports-color"
:
"^2.0.0"
},
"engines"
:
{
"node"
:
">=0.10.0"
}
},
"node_modules/chalk/node_modules/supports-color"
:
{
"version"
:
"2.0.0"
,
"resolved"
:
"https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz"
,
"integrity"
:
"sha512-KKNVtd6pCYgPIKU4cp2733HWYCpplQhddZLBUryaAHou723x+FRzQ5Df824Fj+IyyuiQTRoub4SnIFfIcrp70g=="
,
"engines"
:
{
"node"
:
">=0.8.0"
}
},
"node_modules/chokidar"
:
{
"node_modules/chokidar"
:
{
"version"
:
"3.5.3"
,
"version"
:
"3.5.3"
,
"resolved"
:
"https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz"
,
"resolved"
:
"https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz"
,
...
@@ -343,6 +383,14 @@
...
@@ -343,6 +383,14 @@
"resolved"
:
"https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz"
,
"resolved"
:
"https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz"
,
"integrity"
:
"sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow=="
"integrity"
:
"sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow=="
},
},
"node_modules/escape-string-regexp"
:
{
"version"
:
"1.0.5"
,
"resolved"
:
"https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz"
,
"integrity"
:
"sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg=="
,
"engines"
:
{
"node"
:
">=0.8.0"
}
},
"node_modules/etag"
:
{
"node_modules/etag"
:
{
"version"
:
"1.8.1"
,
"version"
:
"1.8.1"
,
"resolved"
:
"https://registry.npmjs.org/etag/-/etag-1.8.1.tgz"
,
"resolved"
:
"https://registry.npmjs.org/etag/-/etag-1.8.1.tgz"
,
...
@@ -526,6 +574,17 @@
...
@@ -526,6 +574,17 @@
"node"
:
">= 0.4.0"
"node"
:
">= 0.4.0"
}
}
},
},
"node_modules/has-ansi"
:
{
"version"
:
"2.0.0"
,
"resolved"
:
"https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz"
,
"integrity"
:
"sha512-C8vBJ8DwUCx19vhm7urhTuUsr4/IyP6l4VzNQDv+ryHQObW3TTTp9yB68WpYgRe2bbaGuZ/se74IqFeVnMnLZg=="
,
"dependencies"
:
{
"ansi-regex"
:
"^2.0.0"
},
"engines"
:
{
"node"
:
">=0.10.0"
}
},
"node_modules/has-flag"
:
{
"node_modules/has-flag"
:
{
"version"
:
"3.0.0"
,
"version"
:
"3.0.0"
,
"resolved"
:
"https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz"
,
"resolved"
:
"https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz"
,
...
@@ -1343,6 +1402,17 @@
...
@@ -1343,6 +1402,17 @@
"resolved"
:
"https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz"
,
"resolved"
:
"https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz"
,
"integrity"
:
"sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
"integrity"
:
"sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g=="
},
},
"node_modules/strip-ansi"
:
{
"version"
:
"3.0.1"
,
"resolved"
:
"https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz"
,
"integrity"
:
"sha512-VhumSSbBqDTP8p2ZLKj40UjBCV4+v8bUSEpUb4KjRgWk9pbqGF4REFj6KEagidb2f/M6AzC0EmFyDNGaw9OCzg=="
,
"dependencies"
:
{
"ansi-regex"
:
"^2.0.0"
},
"engines"
:
{
"node"
:
">=0.10.0"
}
},
"node_modules/supports-color"
:
{
"node_modules/supports-color"
:
{
"version"
:
"5.5.0"
,
"version"
:
"5.5.0"
,
"resolved"
:
"https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz"
,
"resolved"
:
"https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz"
,
...
@@ -1373,6 +1443,18 @@
...
@@ -1373,6 +1443,18 @@
"node"
:
">=0.6"
"node"
:
">=0.6"
}
}
},
},
"node_modules/torch"
:
{
"version"
:
"0.2.7"
,
"resolved"
:
"https://registry.npmjs.org/torch/-/torch-0.2.7.tgz"
,
"integrity"
:
"sha512-yTv7qWKGg00hMDv0pyBgRjubbf4eygzzrjKPKRC9rbPCKBF0jd+cxnzIoN+pCHgGf2EQbd0jGyy1X7h5BIqjEA=="
,
"deprecated"
:
"Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."
,
"dependencies"
:
{
"chalk"
:
"^1.1.3"
},
"engines"
:
{
"node"
:
">= 0.8.4"
}
},
"node_modules/touch"
:
{
"node_modules/touch"
:
{
"version"
:
"3.1.0"
,
"version"
:
"3.1.0"
,
"resolved"
:
"https://registry.npmjs.org/touch/-/touch-3.1.0.tgz"
,
"resolved"
:
"https://registry.npmjs.org/touch/-/touch-3.1.0.tgz"
,
...
@@ -1522,6 +1604,16 @@
...
@@ -1522,6 +1604,16 @@
"negotiator"
:
"0.6.3"
"negotiator"
:
"0.6.3"
}
}
},
},
"ansi-regex"
:
{
"version"
:
"2.1.1"
,
"resolved"
:
"https://registry.npmjs.org/ansi-regex/-/ansi-regex-2.1.1.tgz"
,
"integrity"
:
"sha512-TIGnTpdo+E3+pCyAluZvtED5p5wCqLdezCyhPZzKPcxvFplEt4i+W7OONCKgeZFT3+y5NZZfOOS/Bdcanm1MYA=="
},
"ansi-styles"
:
{
"version"
:
"2.2.1"
,
"resolved"
:
"https://registry.npmjs.org/ansi-styles/-/ansi-styles-2.2.1.tgz"
,
"integrity"
:
"sha512-kmCevFghRiWM7HB5zTPULl4r9bVFSWjz62MhqizDGUrq2NWuNMQyuv4tHHoKJHs69M/MF64lEcHdYIocrdWQYA=="
},
"anymatch"
:
{
"anymatch"
:
{
"version"
:
"3.1.3"
,
"version"
:
"3.1.3"
,
"resolved"
:
"https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz"
,
"resolved"
:
"https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz"
,
...
@@ -1629,6 +1721,25 @@
...
@@ -1629,6 +1721,25 @@
"get-intrinsic"
:
"^1.0.2"
"get-intrinsic"
:
"^1.0.2"
}
}
},
},
"chalk"
:
{
"version"
:
"1.1.3"
,
"resolved"
:
"https://registry.npmjs.org/chalk/-/chalk-1.1.3.tgz"
,
"integrity"
:
"sha512-U3lRVLMSlsCfjqYPbLyVv11M9CPW4I728d6TCKMAOJueEeB9/8o+eSsMnxPJD+Q+K909sdESg7C+tIkoH6on1A=="
,
"requires"
:
{
"ansi-styles"
:
"^2.2.1"
,
"escape-string-regexp"
:
"^1.0.2"
,
"has-ansi"
:
"^2.0.0"
,
"strip-ansi"
:
"^3.0.0"
,
"supports-color"
:
"^2.0.0"
},
"dependencies"
:
{
"supports-color"
:
{
"version"
:
"2.0.0"
,
"resolved"
:
"https://registry.npmjs.org/supports-color/-/supports-color-2.0.0.tgz"
,
"integrity"
:
"sha512-KKNVtd6pCYgPIKU4cp2733HWYCpplQhddZLBUryaAHou723x+FRzQ5Df824Fj+IyyuiQTRoub4SnIFfIcrp70g=="
}
}
},
"chokidar"
:
{
"chokidar"
:
{
"version"
:
"3.5.3"
,
"version"
:
"3.5.3"
,
"resolved"
:
"https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz"
,
"resolved"
:
"https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz"
,
...
@@ -1743,6 +1854,11 @@
...
@@ -1743,6 +1854,11 @@
"resolved"
:
"https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz"
,
"resolved"
:
"https://registry.npmjs.org/escape-html/-/escape-html-1.0.3.tgz"
,
"integrity"
:
"sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow=="
"integrity"
:
"sha512-NiSupZ4OeuGwr68lGIeym/ksIZMJodUGOSCZ/FSnTxcrekbvqrgdUxlJOMpijaKZVjAJrWrGs/6Jy8OMuyj9ow=="
},
},
"escape-string-regexp"
:
{
"version"
:
"1.0.5"
,
"resolved"
:
"https://registry.npmjs.org/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz"
,
"integrity"
:
"sha512-vbRorB5FUQWvla16U8R/qgaFIya2qGzwDrNmCZuYKrbdSUMG6I1ZCGQRefkRVhuOkIGVne7BQ35DSfo1qvJqFg=="
},
"etag"
:
{
"etag"
:
{
"version"
:
"1.8.1"
,
"version"
:
"1.8.1"
,
"resolved"
:
"https://registry.npmjs.org/etag/-/etag-1.8.1.tgz"
,
"resolved"
:
"https://registry.npmjs.org/etag/-/etag-1.8.1.tgz"
,
...
@@ -1887,6 +2003,14 @@
...
@@ -1887,6 +2003,14 @@
"function-bind"
:
"^1.1.1"
"function-bind"
:
"^1.1.1"
}
}
},
},
"has-ansi"
:
{
"version"
:
"2.0.0"
,
"resolved"
:
"https://registry.npmjs.org/has-ansi/-/has-ansi-2.0.0.tgz"
,
"integrity"
:
"sha512-C8vBJ8DwUCx19vhm7urhTuUsr4/IyP6l4VzNQDv+ryHQObW3TTTp9yB68WpYgRe2bbaGuZ/se74IqFeVnMnLZg=="
,
"requires"
:
{
"ansi-regex"
:
"^2.0.0"
}
},
"has-flag"
:
{
"has-flag"
:
{
"version"
:
"3.0.0"
,
"version"
:
"3.0.0"
,
"resolved"
:
"https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz"
,
"resolved"
:
"https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz"
,
...
@@ -2489,6 +2613,14 @@
...
@@ -2489,6 +2613,14 @@
}
}
}
}
},
},
"strip-ansi"
:
{
"version"
:
"3.0.1"
,
"resolved"
:
"https://registry.npmjs.org/strip-ansi/-/strip-ansi-3.0.1.tgz"
,
"integrity"
:
"sha512-VhumSSbBqDTP8p2ZLKj40UjBCV4+v8bUSEpUb4KjRgWk9pbqGF4REFj6KEagidb2f/M6AzC0EmFyDNGaw9OCzg=="
,
"requires"
:
{
"ansi-regex"
:
"^2.0.0"
}
},
"supports-color"
:
{
"supports-color"
:
{
"version"
:
"5.5.0"
,
"version"
:
"5.5.0"
,
"resolved"
:
"https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz"
,
"resolved"
:
"https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz"
,
...
@@ -2510,6 +2642,14 @@
...
@@ -2510,6 +2642,14 @@
"resolved"
:
"https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz"
,
"resolved"
:
"https://registry.npmjs.org/toidentifier/-/toidentifier-1.0.1.tgz"
,
"integrity"
:
"sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA=="
"integrity"
:
"sha512-o5sSPKEkg/DIQNmH43V0/uerLrpzVedkUh8tGNvaeXpfpuwjKenlSox/2O/BTlZUtEe+JG7s5YhEz608PlAHRA=="
},
},
"torch"
:
{
"version"
:
"0.2.7"
,
"resolved"
:
"https://registry.npmjs.org/torch/-/torch-0.2.7.tgz"
,
"integrity"
:
"sha512-yTv7qWKGg00hMDv0pyBgRjubbf4eygzzrjKPKRC9rbPCKBF0jd+cxnzIoN+pCHgGf2EQbd0jGyy1X7h5BIqjEA=="
,
"requires"
:
{
"chalk"
:
"^1.1.3"
}
},
"touch"
:
{
"touch"
:
{
"version"
:
"3.1.0"
,
"version"
:
"3.1.0"
,
"resolved"
:
"https://registry.npmjs.org/touch/-/touch-3.1.0.tgz"
,
"resolved"
:
"https://registry.npmjs.org/touch/-/touch-3.1.0.tgz"
,
...
...
Project/Backend/Server_Node/package.json
View file @
44218348
...
@@ -21,6 +21,7 @@
...
@@ -21,6 +21,7 @@
"multer"
:
"^1.4.5-lts.1"
,
"multer"
:
"^1.4.5-lts.1"
,
"nodemailer"
:
"^6.9.1"
,
"nodemailer"
:
"^6.9.1"
,
"nodemon"
:
"^2.0.22"
,
"nodemon"
:
"^2.0.22"
,
"torch"
:
"^0.2.7"
,
"uuid"
:
"^9.0.0"
"uuid"
:
"^9.0.0"
}
}
}
}
Project/Backend/Server_Node/prediction_config/C1T1/predict.py
0 → 100644
View file @
44218348
import
sys
import
io
import
base64
import
torch
import
torchvision.transforms
as
transforms
from
PIL
import
Image
import
torch.nn
as
nn
import
torch.nn.functional
as
F
import
numpy
as
np
class
theCNN
(
nn
.
Module
):
def
__init__
(
self
):
super
()
.
__init__
()
self
.
conv01
=
nn
.
Conv2d
(
in_channels
=
1
,
out_channels
=
10
,
kernel_size
=
5
,
stride
=
1
,
padding
=
1
)
self
.
dropout1
=
nn
.
Dropout
(
0.2
)
# Add dropout layer
self
.
conv02
=
nn
.
Conv2d
(
in_channels
=
10
,
out_channels
=
20
,
kernel_size
=
5
,
stride
=
1
,
padding
=
1
)
self
.
dropout2
=
nn
.
Dropout
(
0.2
)
# Add dropout layer
expectedSize
=
np
.
floor
((
73
+
2
*
0
-
1
)
/
1
)
+
1
expectedSize
=
20
*
int
(
expectedSize
**
2
)
self
.
fc01
=
nn
.
Linear
(
expectedSize
,
50
)
self
.
output
=
nn
.
Linear
(
50
,
16
)
def
forward
(
self
,
x
):
# convo -> maxpool -> relu
x
=
F
.
relu
(
F
.
max_pool2d
(
self
.
conv01
(
x
),
2
))
# convo -> maxpool -> relu
x
=
F
.
relu
(
F
.
max_pool2d
(
self
.
conv02
(
x
),
2
))
nUnits
=
x
.
shape
.
numel
()
/
x
.
shape
[
0
]
x
=
x
.
view
(
-
1
,
int
(
nUnits
))
x
=
F
.
relu
(
self
.
fc01
(
x
))
return
torch
.
softmax
(
self
.
output
(
x
),
axis
=
1
)
# Load the trained model
model
=
theCNN
()
# Instantiate your model class
model
.
load_state_dict
(
torch
.
load
(
'D:/SLIIT_Y4_Research_Module/Research/Project/2023-029/Project/Backend/Server_Node/prediction_config/C1T1/trained_model_modified.pth'
,
map_location
=
torch
.
device
(
'cpu'
)))
model
.
eval
()
# Read image data and target class from standard input
input_data
=
sys
.
stdin
.
readlines
()
image_data
=
input_data
[
0
]
.
strip
()
.
encode
()
# Convert to bytes
target_class
=
input_data
[
1
]
.
strip
()
# Preprocess the image
# image_data = base64.b64decode(sys.argv[1])
# image = Image.open(io.BytesIO(image_data))
image
=
Image
.
open
(
io
.
BytesIO
(
base64
.
b64decode
(
image_data
)))
transform
=
transforms
.
Compose
([
transforms
.
Resize
((
300
,
300
)),
transforms
.
Grayscale
(
num_output_channels
=
1
),
transforms
.
ToTensor
(),
transforms
.
Normalize
(
mean
=
[
0.5
],
std
=
[
0.5
]),
])
image_tensor
=
transform
(
image
)
.
unsqueeze
(
0
)
# Predict the class
with
torch
.
no_grad
():
outputs
=
model
(
image_tensor
)
predicted_class
=
torch
.
argmax
(
outputs
[
0
])
.
item
()
confidence
=
outputs
[
0
][
predicted_class
]
.
item
()
# Calculate similarity or confidence percentage
# target_class = sys.argv[2].lower() # Class name passed from the API
similarity
=
100
*
confidence
print
(
f
"{predicted_class},{similarity:.2f}"
)
Project/Backend/Server_Node/prediction_config/C1T1/trained_model_modified.pth
0 → 100644
View file @
44218348
File added
Project/Backend/Server_Node/routes/marksCalculator.routes.js
0 → 100644
View file @
44218348
import
express
from
"
express
"
;
import
multer
from
"
multer
"
;
import
{
marksCalculator
}
from
"
../controllers/marksCalculator.controller.js
"
;
// Set up storage for uploaded images
const
storage
=
multer
.
memoryStorage
();
const
upload
=
multer
({
storage
:
storage
});
const
router
=
express
.
Router
();
router
.
post
(
'
/curriculum/tutorial
'
,
upload
.
single
(
'
image
'
),
marksCalculator
)
export
default
router
;
\ No newline at end of file
Project/Backend/Server_Node/server.js
View file @
44218348
...
@@ -8,6 +8,7 @@ import mongoose from "mongoose";
...
@@ -8,6 +8,7 @@ import mongoose from "mongoose";
import
curriculumRoutes
from
"
./routes/curriculum.routes.js
"
;
import
curriculumRoutes
from
"
./routes/curriculum.routes.js
"
;
import
feedbackRoutes
from
"
./routes/feedback.routes.js
"
;
import
feedbackRoutes
from
"
./routes/feedback.routes.js
"
;
import
leaderboardRoutes
from
"
./routes/leaderboard.routes.js
"
;
import
leaderboardRoutes
from
"
./routes/leaderboard.routes.js
"
;
import
marksCalculatorRoutes
from
"
./routes/marksCalculator.routes.js
"
;
import
translateRoutes
from
"
./routes/translate.routes.js
"
;
import
translateRoutes
from
"
./routes/translate.routes.js
"
;
import
tutorialRoutes
from
"
./routes/tutorial.routes.js
"
;
import
tutorialRoutes
from
"
./routes/tutorial.routes.js
"
;
import
userRoutes
from
"
./routes/user.routes.js
"
;
import
userRoutes
from
"
./routes/user.routes.js
"
;
...
@@ -33,6 +34,7 @@ app.use("/rest_node/tutorial", tutorialRoutes);
...
@@ -33,6 +34,7 @@ app.use("/rest_node/tutorial", tutorialRoutes);
app
.
use
(
"
/rest_node/user-progress
"
,
userProgressRoutes
);
app
.
use
(
"
/rest_node/user-progress
"
,
userProgressRoutes
);
app
.
use
(
"
/rest_node/feedback
"
,
feedbackRoutes
);
app
.
use
(
"
/rest_node/feedback
"
,
feedbackRoutes
);
app
.
use
(
"
/rest_node/leaderboard
"
,
leaderboardRoutes
);
app
.
use
(
"
/rest_node/leaderboard
"
,
leaderboardRoutes
);
app
.
use
(
"
/rest_node/marks-calculator
"
,
marksCalculatorRoutes
);
const
CONNECTION_URL
=
`mongodb+srv://
${
process
.
env
.
DB_USERNAME
}
:
${
process
.
env
.
DB_PASSWORD
}
@researchmanagement-appl.vzhn4.mongodb.net/?retryWrites=true&w=majority`
;
const
CONNECTION_URL
=
`mongodb+srv://
${
process
.
env
.
DB_USERNAME
}
:
${
process
.
env
.
DB_PASSWORD
}
@researchmanagement-appl.vzhn4.mongodb.net/?retryWrites=true&w=majority`
;
const
PORT
=
process
.
env
.
PORT
||
5000
;
const
PORT
=
process
.
env
.
PORT
||
5000
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment