Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
SpeakEzy_Backend
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
Shehan Liyanage
SpeakEzy_Backend
Commits
3b6c555b
Commit
3b6c555b
authored
May 17, 2024
by
Shehan Liyanage
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add all changes
parent
dd70590a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
220 additions
and
0 deletions
+220
-0
.DS_Store
.DS_Store
+0
-0
sign_language_backend/.gitignore
sign_language_backend/.gitignore
+132
-0
sign_language_backend/app.py
sign_language_backend/app.py
+88
-0
sign_language_backend/finalModel.h5
sign_language_backend/finalModel.h5
+0
-0
No files found.
.DS_Store
0 → 100644
View file @
3b6c555b
File added
sign_language_backend/.gitignore
0 → 100644
View file @
3b6c555b
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# IPython
profile_default/
ipython_config.py
# pyenv
.python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or using Docker, you probably want to ignore it.
Pipfile.lock
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# dotenv
.env
.env.*.local
# virtualenv
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyderworkspace
# Rope project settings
.ropeproject
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
# Note: Comment this out if you have project-level dependencies in a `.python-version` file.
.python-version
# Pylint
pylint.log
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
sign_language_backend/app.py
0 → 100644
View file @
3b6c555b
from
flask
import
Flask
,
request
,
jsonify
import
base64
import
cv2
import
numpy
as
np
import
mediapipe
as
mp
import
tensorflow
as
tf
import
logging
app
=
Flask
(
__name__
)
# Load the model
model
=
tf
.
keras
.
models
.
load_model
(
'./finalModel.h5'
)
mp_holistic
=
mp
.
solutions
.
holistic
holistic
=
mp_holistic
.
Holistic
(
min_detection_confidence
=
0.5
,
min_tracking_confidence
=
0.5
)
sequence
=
[]
sentence
=
[]
predictions
=
[]
threshold
=
0.7
actions
=
[
"haloo"
,
"dannwa"
,
"mama"
,
"obata"
,
"puluwan"
,
"suba"
,
"udaasanak"
]
def
mediapipe_detection
(
image
,
model
):
image
=
cv2
.
cvtColor
(
image
,
cv2
.
COLOR_BGR2RGB
)
image
.
flags
.
writeable
=
False
results
=
model
.
process
(
image
)
image
.
flags
.
writeable
=
True
image
=
cv2
.
cvtColor
(
image
,
cv2
.
COLOR_RGB2BGR
)
return
image
,
results
def
extract_keypoints
(
results
):
pose
=
np
.
array
([[
res
.
x
,
res
.
y
,
res
.
z
,
res
.
visibility
]
for
res
in
results
.
pose_landmarks
.
landmark
])
.
flatten
()
if
results
.
pose_landmarks
else
np
.
zeros
(
33
*
4
)
face
=
np
.
array
([[
res
.
x
,
res
.
y
,
res
.
z
]
for
res
in
results
.
face_landmarks
.
landmark
])
.
flatten
()
if
results
.
face_landmarks
else
np
.
zeros
(
468
*
3
)
lh
=
np
.
array
([[
res
.
x
,
res
.
y
,
res
.
z
]
for
res
in
results
.
left_hand_landmarks
.
landmark
])
.
flatten
()
if
results
.
left_hand_landmarks
else
np
.
zeros
(
21
*
3
)
rh
=
np
.
array
([[
res
.
x
,
res
.
y
,
res
.
z
]
for
res
in
results
.
right_hand_landmarks
.
landmark
])
.
flatten
()
if
results
.
right_hand_landmarks
else
np
.
zeros
(
21
*
3
)
return
np
.
concatenate
([
pose
,
face
,
lh
,
rh
])
@
app
.
route
(
'/endpoint'
,
methods
=
[
'POST'
])
def
process_frame
():
try
:
data
=
request
.
json
frame_data
=
data
[
'frame'
]
# Fix incorrect padding for base64 string
frame_data
+=
"="
*
((
4
-
len
(
frame_data
)
%
4
)
%
4
)
# Decode the base64 string to an image
decoded_data
=
base64
.
b64decode
(
frame_data
)
np_data
=
np
.
frombuffer
(
decoded_data
,
dtype
=
np
.
uint8
)
frame
=
cv2
.
imdecode
(
np_data
,
cv2
.
IMREAD_COLOR
)
if
frame
is
None
:
raise
ValueError
(
"Failed to decode image"
)
# Process the frame with Mediapipe and your model
image
,
results
=
mediapipe_detection
(
frame
,
holistic
)
keypoints
=
extract_keypoints
(
results
)
sequence
.
append
(
keypoints
)
sequence
=
sequence
[
-
50
:]
if
len
(
sequence
)
==
50
:
res
=
model
.
predict
(
np
.
expand_dims
(
sequence
,
axis
=
0
))[
0
]
predictions
.
append
(
np
.
argmax
(
res
))
# Implement your prediction logic
if
np
.
unique
(
predictions
[
-
25
:])[
0
]
==
np
.
argmax
(
res
):
if
res
[
np
.
argmax
(
res
)]
>
threshold
:
if
len
(
sentence
)
>
0
:
if
actions
[
np
.
argmax
(
res
)]
!=
sentence
[
-
1
]:
sentence
.
append
(
actions
[
np
.
argmax
(
res
)])
else
:
sentence
.
append
(
actions
[
np
.
argmax
(
res
)])
if
len
(
sentence
)
>
5
:
sentence
=
sentence
[
-
5
:]
# Print predictions and sentence to the console
print
(
f
"Predicted: {actions[np.argmax(res)]}"
)
print
(
f
"Sentence: {sentence}"
)
return
jsonify
({
'message'
:
'Frame processed'
,
'sentence'
:
sentence
}),
200
except
Exception
as
e
:
logging
.
exception
(
"Exception in /endpoint"
)
return
jsonify
({
'message'
:
'Error processing frame'
,
'error'
:
str
(
e
)}),
500
if
__name__
==
'__main__'
:
app
.
run
(
debug
=
True
,
port
=
8000
)
sign_language_backend/finalModel.h5
0 → 100644
View file @
3b6c555b
File added
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