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
3f692d5a
Commit
3f692d5a
authored
May 19, 2023
by
supundileepa00
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: Make predictions by uploading a image
parent
e2e2a81b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
5 deletions
+50
-5
Project/Backend/Server_Python/.gitignore
Project/Backend/Server_Python/.gitignore
+4
-1
Project/Backend/Server_Python/controllers/__pycache__/translate_controler.cpython-310.pyc
...ntrollers/__pycache__/translate_controler.cpython-310.pyc
+0
-0
Project/Backend/Server_Python/controllers/translate_controler.py
.../Backend/Server_Python/controllers/translate_controler.py
+43
-3
Project/Backend/Server_Python/requirements.txt
Project/Backend/Server_Python/requirements.txt
+3
-1
No files found.
Project/Backend/Server_Python/.gitignore
View file @
3f692d5a
...
...
@@ -11,4 +11,7 @@
*.webm
*.vob
*.m4v
*.ts
\ No newline at end of file
*.ts
files/*
!files/
\ No newline at end of file
Project/Backend/Server_Python/controllers/__pycache__/translate_controler.cpython-310.pyc
View file @
3f692d5a
No preview for this file type
Project/Backend/Server_Python/controllers/translate_controler.py
View file @
3f692d5a
import
base64
import
os
import
cv2
from
fastapi
import
APIRouter
,
File
,
HTTPException
,
UploadFile
import
numpy
as
np
from
pydantic
import
BaseModel
import
tensorflow
as
tf
from
core
import
setup_logger
...
...
@@ -6,19 +12,53 @@ from core import setup_logger
router
=
APIRouter
()
logger
=
setup_logger
()
class
ImageRequest
(
BaseModel
):
image
:
UploadFile
# Load your Keras model
model
=
tf
.
keras
.
models
.
load_model
(
'D:
\
RP
\
SL-Detection-Action-Recognition
\
models
\
model'
)
CLASSES
=
os
.
listdir
(
'D:
\
RP
\
SL-Detection-Action-Recognition
\
data
\
Sn_sign_language_dataset'
)
# list of classes
NUM_CLASSES
=
len
(
CLASSES
)
# number of classes
IMG_SIZE
=
224
# image size
@
router
.
post
(
"/upload/video"
)
async
def
upload_video
(
video
:
UploadFile
=
File
(
...
)):
try
:
# Save the uploaded video to the "uploads" folder
logger
.
info
(
"Received request at root endpoint."
)
file_location
=
f
"files/{video.filename}"
with
open
(
file_location
,
"wb"
)
as
file
:
file
.
write
(
video
.
file
.
read
())
return
{
"
filename"
:
video
.
filename
}
return
{
"
text"
:
"ආආආආආආආ"
}
except
Exception
as
e
:
logger
.
info
(
f
"Failed to upload file. {e}"
)
raise
HTTPException
(
status_code
=
500
,
detail
=
"Failed to upload the video"
)
@
router
.
post
(
'/predict-sign-language'
)
def
predict
(
image_request
:
UploadFile
=
File
(
...
)):
try
:
file_location
=
f
"files/{image_request.filename}"
with
open
(
file_location
,
"wb"
)
as
file
:
file
.
write
(
image_request
.
file
.
read
())
# Load the saved image using OpenCV
img
=
cv2
.
imread
(
file_location
)
img
=
cv2
.
cvtColor
(
img
,
cv2
.
COLOR_BGR2RGB
)
img
=
cv2
.
resize
(
img
,
(
IMG_SIZE
,
IMG_SIZE
))
img
=
np
.
array
([
img
],
dtype
=
np
.
float32
)
/
255.0
# Make prediction
prediction
=
model
.
predict
(
img
)
class_name
=
CLASSES
[
np
.
argmax
(
prediction
)]
return
{
'class_name'
:
class_name
}
except
Exception
as
e
:
logger
.
info
(
f
"Failed to make predictions. {e}"
)
raise
HTTPException
(
status_code
=
500
,
detail
=
"Failed to make predictions"
)
\ No newline at end of file
Project/Backend/Server_Python/requirements.txt
View file @
3f692d5a
fastapi
uvicorn
python-multipart==0.0.6
\ No newline at end of file
python-multipart==0.0.6
tensorflow==2.12.0
opencv-python==4.7.0.72
\ No newline at end of file
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