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
a35b6b73
Commit
a35b6b73
authored
Aug 30, 2023
by
Sumudu-Himasha-Ranaweera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: update
desc : update project
parent
f46f5d41
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
534 additions
and
249 deletions
+534
-249
.vscode/settings.json
.vscode/settings.json
+5
-1
Project/Backend/Server_Python/controllers/video_translate.py
Project/Backend/Server_Python/controllers/video_translate.py
+0
-90
Project/Backend/Server_Python/controllers/video_translate_server.py
...ckend/Server_Python/controllers/video_translate_server.py
+7
-3
Project/Backend/Server_Python/main.py
Project/Backend/Server_Python/main.py
+104
-9
Project/Backend/Server_Python/services/video_to_SignLanguage.py
...t/Backend/Server_Python/services/video_to_SignLanguage.py
+94
-0
Project/Backend/Server_Python/services/video_to_SignLanguage_prev.py
...kend/Server_Python/services/video_to_SignLanguage_prev.py
+181
-0
Project/Backend/Server_Python/services/video_to_sign_language.py
.../Backend/Server_Python/services/video_to_sign_language.py
+0
-83
Project/Frontend/SignConnectPlus/src/pages/services/VideoToSignLanguage.js
...SignConnectPlus/src/pages/services/VideoToSignLanguage.js
+3
-2
Project/Frontend/SignConnectPlus/src/pages/video-to-sign-language/VideoTranslate/VideoTranslate.tsx
.../video-to-sign-language/VideoTranslate/VideoTranslate.tsx
+140
-61
No files found.
.vscode/settings.json
View file @
a35b6b73
...
@@ -3,5 +3,9 @@
...
@@ -3,5 +3,9 @@
"Janith"
,
"Janith"
,
"leaderboard"
,
"leaderboard"
,
"SLIIT"
"SLIIT"
]
],
"[python]"
:
{
"editor.defaultFormatter"
:
"ms-python.black-formatter"
},
"python.formatting.provider"
:
"none"
}
}
\ No newline at end of file
Project/Backend/Server_Python/controllers/video_translate.py
deleted
100644 → 0
View file @
f46f5d41
from
fastapi
import
FastAPI
,
HTTPException
from
pymongo.mongo_client
import
MongoClient
from
pydantic
import
BaseModel
from
typing
import
List
from
bson
import
ObjectId
app
=
FastAPI
()
# Replace with your MongoDB Atlas credentials
username
=
"admin"
password
=
"JppbU6MZeHfOj7sp"
uri
=
f
"mongodb+srv://{username}:{password}@researchmanagement-appl.vzhn4.mongodb.net/?retryWrites=true&w=majority"
client
=
MongoClient
(
uri
)
db
=
client
[
"test"
]
items_collection
=
db
[
"items"
]
class
ItemCreate
(
BaseModel
):
item_name
:
str
item_description
:
str
class
Item
(
BaseModel
):
item_name
:
str
item_description
:
str
_id
:
str
@
app
.
on_event
(
"startup"
)
async
def
startup_db_client
():
app
.
mongodb_client
=
MongoClient
(
uri
)
try
:
app
.
mongodb_client
.
admin
.
command
(
"ping"
)
print
(
"Pinged your deployment. You successfully connected to MongoDB!"
)
except
Exception
as
e
:
print
(
e
)
@
app
.
on_event
(
"shutdown"
)
async
def
shutdown_db_client
():
app
.
mongodb_client
.
close
()
@
app
.
get
(
"/"
)
async
def
read_root
():
return
{
"message"
:
"FastAPI with MongoDB integration"
}
@
app
.
post
(
"/items/"
,
response_model
=
Item
)
async
def
create_item
(
item_create
:
ItemCreate
):
item_data
=
{
"item_name"
:
item_create
.
item_name
,
"item_description"
:
item_create
.
item_description
,
}
result
=
items_collection
.
insert_one
(
item_data
)
if
result
.
inserted_id
:
return
{
**
item_data
,
"_id"
:
str
(
result
.
inserted_id
)}
else
:
raise
HTTPException
(
status_code
=
500
,
detail
=
"Failed to create item"
)
@
app
.
put
(
"/items/{item_id}"
,
response_model
=
Item
)
async
def
update_item
(
item_id
:
str
,
item_update
:
ItemCreate
):
item_object_id
=
ObjectId
(
item_id
)
# Convert item_id to ObjectId
update_data
=
{
"item_name"
:
item_update
.
item_name
,
"item_description"
:
item_update
.
item_description
,
}
result
=
items_collection
.
update_one
({
"_id"
:
item_object_id
},
{
"$set"
:
update_data
})
if
result
.
modified_count
>
0
:
updated_item
=
items_collection
.
find_one
({
"_id"
:
item_object_id
})
return
{
**
updated_item
,
"_id"
:
str
(
updated_item
[
"_id"
])}
else
:
raise
HTTPException
(
status_code
=
404
,
detail
=
"Item not found"
)
@
app
.
get
(
"/items/"
,
response_model
=
List
[
Item
])
async
def
get_all_items
():
items
=
list
(
items_collection
.
find
())
items_with_string_id
=
[{
**
item
,
"_id"
:
str
(
item
[
"_id"
])}
for
item
in
items
]
print
(
items_with_string_id
)
return
items_with_string_id
if
__name__
==
"__main__"
:
import
uvicorn
uvicorn
.
run
(
app
,
host
=
"127.0.0.1"
,
port
=
8000
)
Project/Backend/Server_Python/controllers/video_translate_server.py
View file @
a35b6b73
...
@@ -3,6 +3,7 @@ from pymongo.mongo_client import MongoClient
...
@@ -3,6 +3,7 @@ from pymongo.mongo_client import MongoClient
from
pydantic
import
BaseModel
from
pydantic
import
BaseModel
from
typing
import
List
from
typing
import
List
from
bson
import
ObjectId
from
bson
import
ObjectId
from
datetime
import
datetime
app
=
FastAPI
()
app
=
FastAPI
()
...
@@ -15,6 +16,7 @@ client = MongoClient(uri)
...
@@ -15,6 +16,7 @@ client = MongoClient(uri)
db
=
client
[
"test"
]
db
=
client
[
"test"
]
items_collection
=
db
[
"translated_items"
]
items_collection
=
db
[
"translated_items"
]
class
ItemCreate
(
BaseModel
):
class
ItemCreate
(
BaseModel
):
item_name
:
str
item_name
:
str
item_description
:
str
item_description
:
str
...
@@ -25,6 +27,7 @@ class Item(BaseModel):
...
@@ -25,6 +27,7 @@ class Item(BaseModel):
item_description
:
str
item_description
:
str
_id
:
str
_id
:
str
class
TranslatedItemCreate
(
BaseModel
):
class
TranslatedItemCreate
(
BaseModel
):
translated_integer_si
:
str
translated_integer_si
:
str
...
@@ -48,11 +51,13 @@ async def shutdown_db_client():
...
@@ -48,11 +51,13 @@ async def shutdown_db_client():
async
def
read_root
():
async
def
read_root
():
return
{
"message"
:
"FastAPI with MongoDB integration"
}
return
{
"message"
:
"FastAPI with MongoDB integration"
}
# send tranlated integer to mongodb
# send tranlated integer to mongodb
@
app
.
post
(
"/translated_items/"
,
response_model
=
TranslatedItemCreate
)
@
app
.
post
(
"/translated_items/"
,
response_model
=
TranslatedItemCreate
)
async
def
create_translated_item
(
translated_item_create
:
TranslatedItemCreate
):
async
def
create_translated_item
(
translated_item_create
:
TranslatedItemCreate
):
translated_item_data
=
{
translated_item_data
=
{
"translated_integer_si"
:
translated_item_create
.
translated_integer_si
,
"translated_integer_si"
:
translated_item_create
.
translated_integer_si
,
"timestamp"
:
datetime
.
utcnow
(),
}
}
result
=
items_collection
.
insert_one
(
translated_item_data
)
result
=
items_collection
.
insert_one
(
translated_item_data
)
if
result
.
inserted_id
:
if
result
.
inserted_id
:
...
@@ -85,7 +90,6 @@ async def get_all_items():
...
@@ -85,7 +90,6 @@ async def get_all_items():
return
items_with_string_id
return
items_with_string_id
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
import
uvicorn
import
uvicorn
...
...
Project/Backend/Server_Python/main.py
View file @
a35b6b73
...
@@ -4,7 +4,6 @@ from fastapi.responses import RedirectResponse
...
@@ -4,7 +4,6 @@ from fastapi.responses import RedirectResponse
from
fastapi.middleware.cors
import
CORSMiddleware
from
fastapi.middleware.cors
import
CORSMiddleware
from
core
import
setup_logger
from
core
import
setup_logger
app
=
FastAPI
()
app
=
FastAPI
()
logger
=
setup_logger
()
logger
=
setup_logger
()
...
@@ -19,13 +18,109 @@ origins = [
...
@@ -19,13 +18,109 @@ origins = [
"http://localhost:8080"
,
"http://localhost:8080"
,
]
]
app
.
add_middleware
(
CORSMiddleware
,
app
.
add_middleware
(
CORSMiddleware
,
allow_origins
=
origins
,
allow_origins
=
origins
,
allow_credentials
=
True
,
allow_credentials
=
True
,
allow_methods
=
[
"*"
],
allow_methods
=
[
"*"
],
allow_headers
=
[
"*"
])
allow_headers
=
[
"*"
],
)
@
app
.
get
(
'/'
)
@
app
.
get
(
"/"
)
async
def
root
():
async
def
root
():
url
=
app
.
docs_url
or
'/docs'
url
=
app
.
docs_url
or
"/docs"
return
RedirectResponse
(
url
)
return
RedirectResponse
(
url
)
# import io
# import os
# import subprocess
# import tkinter as tk
# import urllib.parse
# from tkinter import filedialog, messagebox, scrolledtext
# from typing import List
# import moviepy.editor as mp
# import requests
# import speech_recognition as sr
# from bson import ObjectId
# from fastapi import FastAPI, File, UploadFile
# from fastapi.responses import JSONResponse
# # Define a dictionary to map Sinhala Unicode to integers
# unicode_to_int_mapping = {"මම": 1, "හෙට": 2, "යනවා": 3, "මං": 4}
# def translate_text(text, target_language):
# url = "https://translate.googleapis.com/translate_a/single"
# params = {
# "client": "gtx",
# "sl": "auto",
# "tl": target_language,
# "dt": "t",
# "q": text,
# }
# response = requests.get(url, params=params)
# translation_data = response.json()
# translated_text = translation_data[0][0][0]
# return translated_text
# # send to service.py
# def send_to_service(translated_integer_si):
# url = "http://127.0.0.1:8000/translated_items/"
# data = {
# "translated_integer_si": translated_integer_si,
# }
# response = requests.post(url, json=data)
# if response.status_code == 200:
# print("Data sent to server successfully")
# else:
# print("Failed to send data to server")
# @app.get("/rest_pyton/welcome")
# async def root():
# return {"message": "Hello, World!"}
# @app.post("/rest_pyton/uploaded_video")
# async def uploaded_video(file: UploadFile = File(...)):
# try:
# # Process the uploaded video
# video_content = await file.read()
# temp_video_path = "temp_video.mp4"
# with open(temp_video_path, "wb") as temp_video_file:
# temp_video_file.write(video_content)
# audio_save_path = "audio.wav"
# video = mp.VideoFileClip(temp_video_path)
# audio = video.audio
# audio.write_audiofile(audio_save_path)
# r = sr.Recognizer()
# with sr.AudioFile(audio_save_path) as source:
# audio = r.record(source)
# recognized_text = r.recognize_google(audio, language="si-LK")
# translated_text_si = translate_text(recognized_text, "si")
# translated_text_en = translate_text(recognized_text, "en")
# translated_integer_si = " ".join(
# str(unicode_to_int_mapping.get(word, 0))
# for word in translated_text_si.split()
# )
# print("Translated Integer (Si):", translated_integer_si)
# send_to_service(translated_integer_si)
# return JSONResponse(
# content={
# "translated_text_si": translated_text_si,
# "translated_text_en": translated_text_en,
# }
# )
# # return JSONResponse(content={"translated_text_si": "test"})
# except Exception as e:
# return JSONResponse(content={"error": str(e)}, status_code=500)
Project/Backend/Server_Python/services/video_t
ranslat
e.py
→
Project/Backend/Server_Python/services/video_t
o_SignLanguag
e.py
View file @
a35b6b73
import
moviepy.editor
as
mp
import
io
import
speech_recognition
as
sr
import
os
import
subprocess
import
tkinter
as
tk
import
tkinter
as
tk
from
tkinter
import
filedialog
import
urllib.parse
from
tkinter
import
messagebox
from
tkinter
import
filedialog
,
messagebox
,
scrolledtext
from
tkinter
import
scrolledtext
from
typing
import
List
import
moviepy.editor
as
mp
import
requests
import
requests
import
speech_recognition
as
sr
from
bson
import
ObjectId
from
bson
import
ObjectId
import
urllib.parse
from
fastapi
import
FastAPI
,
File
,
UploadFile
import
subprocess
from
fastapi.responses
import
JSONResponse
app
=
FastAPI
()
# Define a dictionary to map Sinhala Unicode to integers
# Define a dictionary to map Sinhala Unicode to integers
unicode_to_int_mapping
=
{
unicode_to_int_mapping
=
{
"මම"
:
1
,
"හෙට"
:
2
,
"යනවා"
:
3
,
"මං"
:
4
}
"මම"
:
1
,
"හෙට"
:
2
,
"යනවා"
:
3
,
"මං"
:
4
}
def
translate_text
(
text
,
target_language
):
def
translate_text
(
text
,
target_language
):
url
=
"https://translate.googleapis.com/translate_a/single"
url
=
"https://translate.googleapis.com/translate_a/single"
...
@@ -24,13 +26,14 @@ def translate_text(text, target_language):
...
@@ -24,13 +26,14 @@ def translate_text(text, target_language):
"sl"
:
"auto"
,
"sl"
:
"auto"
,
"tl"
:
target_language
,
"tl"
:
target_language
,
"dt"
:
"t"
,
"dt"
:
"t"
,
"q"
:
text
"q"
:
text
,
}
}
response
=
requests
.
get
(
url
,
params
=
params
)
response
=
requests
.
get
(
url
,
params
=
params
)
translation_data
=
response
.
json
()
translation_data
=
response
.
json
()
translated_text
=
translation_data
[
0
][
0
][
0
]
translated_text
=
translation_data
[
0
][
0
][
0
]
return
translated_text
return
translated_text
# send to service.py
# send to service.py
def
send_to_service
(
translated_integer_si
):
def
send_to_service
(
translated_integer_si
):
url
=
"http://127.0.0.1:8000/translated_items/"
url
=
"http://127.0.0.1:8000/translated_items/"
...
@@ -44,15 +47,23 @@ def send_to_service(translated_integer_si):
...
@@ -44,15 +47,23 @@ def send_to_service(translated_integer_si):
print
(
"Failed to send data to server"
)
print
(
"Failed to send data to server"
)
def
convert_video
():
# Define a route for the "Hello, World!" endpoint
video_path
=
filedialog
.
askopenfilename
(
filetypes
=
[(
"Video Files"
,
"*.mp4"
)])
@
app
.
get
(
"/"
)
if
not
video_path
:
def
read_root
():
messagebox
.
showwarning
(
"Warning"
,
"No video file selected."
)
return
{
"message"
:
"Hello, World!"
}
return
@
app
.
post
(
"/uploaded_video"
)
async
def
uploaded_video
(
file
:
UploadFile
=
File
(
...
)):
try
:
try
:
# Process the uploaded video
video_content
=
await
file
.
read
()
temp_video_path
=
"temp_video.mp4"
with
open
(
temp_video_path
,
"wb"
)
as
temp_video_file
:
temp_video_file
.
write
(
video_content
)
audio_save_path
=
"audio.wav"
audio_save_path
=
"audio.wav"
video
=
mp
.
VideoFileClip
(
video_path
)
video
=
mp
.
VideoFileClip
(
temp_
video_path
)
audio
=
video
.
audio
audio
=
video
.
audio
audio
.
write_audiofile
(
audio_save_path
)
audio
.
write_audiofile
(
audio_save_path
)
...
@@ -60,46 +71,24 @@ def convert_video():
...
@@ -60,46 +71,24 @@ def convert_video():
with
sr
.
AudioFile
(
audio_save_path
)
as
source
:
with
sr
.
AudioFile
(
audio_save_path
)
as
source
:
audio
=
r
.
record
(
source
)
audio
=
r
.
record
(
source
)
recognized_text
=
r
.
recognize_google
(
audio
,
language
=
'si-LK'
)
recognized_text
=
r
.
recognize_google
(
audio
,
language
=
"si-LK"
)
translated_text_si
=
translate_text
(
recognized_text
,
"si"
)
translated_text_si
=
translate_text
(
recognized_text
,
"si"
)
translated_text_en
=
translate_text
(
recognized_text
,
"en"
)
translated_text_en
=
translate_text
(
recognized_text
,
"en"
)
# Get the integer values and join them into a single string
translated_integer_si
=
" "
.
join
(
translated_integer_si
=
' '
.
join
(
str
(
unicode_to_int_mapping
.
get
(
word
,
0
))
for
word
in
translated_text_si
.
split
(
))
str
(
unicode_to_int_mapping
.
get
(
word
,
0
))
print
(
"Translated Integer (Si):"
,
translated_integer_si
)
# Print the translated integer
for
word
in
translated_text_si
.
split
()
)
send_to_service
(
translated_integer_si
)
# Sending translated_integer_si
print
(
"Translated Integer (Si):"
,
translated_integer_si
)
textarea_si
.
delete
(
'1.0'
,
tk
.
END
)
send_to_service
(
translated_integer_si
)
textarea_en
.
delete
(
'1.0'
,
tk
.
END
)
textarea_si
.
insert
(
tk
.
END
,
f
"Translated Integer: {translated_integer_si}
\n
{translated_text_si}"
)
textarea_en
.
insert
(
tk
.
END
,
translated_text_en
)
return
JSONResponse
(
content
=
{
"translated_text_si"
:
translated_text_si
,
"translated_text_en"
:
translated_text_en
,
}
)
# return JSONResponse(content={"translated_text_si": "test"})
except
Exception
as
e
:
except
Exception
as
e
:
messagebox
.
showerror
(
"Error"
,
str
(
e
))
return
JSONResponse
(
content
=
{
"error"
:
str
(
e
)},
status_code
=
500
)
print
(
"Error during video conversion:"
,
e
)
if
__name__
==
"__main__"
:
# subprocess.Popen(["uvicorn", "main:app", "--host", "127.0.0.1", "--port", "8050"])
window
=
tk
.
Tk
()
window
.
title
(
"Video Translation"
)
window
.
geometry
(
"800x600"
)
title_label
=
tk
.
Label
(
window
,
text
=
"Video Translation"
,
font
=
(
"Arial"
,
16
,
"bold"
))
title_label
.
pack
(
pady
=
10
)
convert_button
=
tk
.
Button
(
window
,
text
=
"Convert Video"
,
command
=
convert_video
)
convert_button
.
pack
(
pady
=
10
)
textarea_si_label
=
tk
.
Label
(
window
,
text
=
"Sinhala Unicode Translation"
)
textarea_si_label
.
pack
()
textarea_si
=
scrolledtext
.
ScrolledText
(
window
,
wrap
=
tk
.
WORD
,
width
=
80
,
height
=
10
)
textarea_si
.
pack
()
textarea_en_label
=
tk
.
Label
(
window
,
text
=
"Singlish Translation"
)
textarea_en_label
.
pack
()
textarea_en
=
scrolledtext
.
ScrolledText
(
window
,
wrap
=
tk
.
WORD
,
width
=
80
,
height
=
10
)
textarea_en
.
pack
()
window
.
mainloop
()
Project/Backend/Server_Python/services/video_to_SignLanguage_prev.py
0 → 100644
View file @
a35b6b73
import
moviepy.editor
as
mp
import
speech_recognition
as
sr
import
tkinter
as
tk
from
tkinter
import
filedialog
from
tkinter
import
messagebox
from
tkinter
import
scrolledtext
import
requests
from
bson
import
ObjectId
import
urllib.parse
import
subprocess
from
fastapi
import
FastAPI
,
File
,
UploadFile
from
fastapi.responses
import
JSONResponse
from
typing
import
List
import
io
app
=
FastAPI
()
# Define a dictionary to map Sinhala Unicode to integers
unicode_to_int_mapping
=
{
"මම"
:
1
,
"හෙට"
:
2
,
"යනවා"
:
3
,
"මං"
:
4
}
def
translate_text
(
text
,
target_language
):
url
=
"https://translate.googleapis.com/translate_a/single"
params
=
{
"client"
:
"gtx"
,
"sl"
:
"auto"
,
"tl"
:
target_language
,
"dt"
:
"t"
,
"q"
:
text
,
}
response
=
requests
.
get
(
url
,
params
=
params
)
translation_data
=
response
.
json
()
translated_text
=
translation_data
[
0
][
0
][
0
]
return
translated_text
# send to service.py
def
send_to_service
(
translated_integer_si
):
url
=
"http://127.0.0.1:8000/translated_items/"
data
=
{
"translated_integer_si"
:
translated_integer_si
,
}
response
=
requests
.
post
(
url
,
json
=
data
)
if
response
.
status_code
==
200
:
print
(
"Data sent to server successfully"
)
else
:
print
(
"Failed to send data to server"
)
# get request from frontend
@
app
.
post
(
"/uploaded_video/"
)
async
def
uploaded_video
(
file
:
UploadFile
=
File
(
...
)):
try
:
# Process the video here
# ... Extract audio, recognize speech, perform translation ...
# Example response with translated results
translated_text_si
=
"Translated Sinhala Text"
translated_text_en
=
"Translated English Text"
return
JSONResponse
(
content
=
{
"translated_text_si"
:
translated_text_si
,
"translated_text_en"
:
translated_text_en
,
}
)
except
Exception
as
e
:
return
JSONResponse
(
content
=
{
"error"
:
str
(
e
)},
status_code
=
500
)
def
convert_video
():
video_path
=
filedialog
.
askopenfilename
(
filetypes
=
[(
"Video Files"
,
"*.mp4"
)])
if
not
video_path
:
messagebox
.
showwarning
(
"Warning"
,
"No video file selected."
)
return
# video_file = request.files['video']
# if video_file:
# # Save the video file and perform translation
# video_path = "uploaded_video.mp4" # Save the video temporarily
# video_file.save(video_path)
try
:
audio_save_path
=
"audio.wav"
video
=
mp
.
VideoFileClip
(
video_path
)
audio
=
video
.
audio
audio
.
write_audiofile
(
audio_save_path
)
r
=
sr
.
Recognizer
()
with
sr
.
AudioFile
(
audio_save_path
)
as
source
:
audio
=
r
.
record
(
source
)
recognized_text
=
r
.
recognize_google
(
audio
,
language
=
"si-LK"
)
translated_text_si
=
translate_text
(
recognized_text
,
"si"
)
translated_text_en
=
translate_text
(
recognized_text
,
"en"
)
# Get the integer values and join them into a single string
translated_integer_si
=
" "
.
join
(
str
(
unicode_to_int_mapping
.
get
(
word
,
0
))
for
word
in
translated_text_si
.
split
()
)
print
(
"Translated Integer (Si):"
,
translated_integer_si
)
# Print the translated integer
send_to_service
(
translated_integer_si
)
# Sending translated_integer_si
# textarea_si.delete('1.0', tk.END)
# textarea_en.delete('1.0', tk.END)
# textarea_si.insert(tk.END, f"Translated Integer: {translated_integer_si}\n{translated_text_si}")
# textarea_en.insert(tk.END, translated_text_en)
except
Exception
as
e
:
messagebox
.
showerror
(
"Error"
,
str
(
e
))
print
(
"Error during video conversion:"
,
e
)
# if __name__ == "__main__":
# # subprocess.Popen(["uvicorn", "main:app", "--host", "127.0.0.1", "--port", "8050"])
# window = tk.Tk()
# window.title("Video Translation")
# window.geometry("800x600")
# title_label = tk.Label(window, text="Video Translation", font=("Arial", 16, "bold"))
# title_label.pack(pady=10)
# convert_button = tk.Button(window, text="Convert Video", command=convert_video)
# convert_button.pack(pady=10)
# textarea_si_label = tk.Label(window, text="Sinhala Unicode Translation")
# textarea_si_label.pack()
# textarea_si = scrolledtext.ScrolledText(window, wrap=tk.WORD, width=80, height=10)
# textarea_si.pack()
# textarea_en_label = tk.Label(window, text="Singlish Translation")
# textarea_en_label.pack()
# textarea_en = scrolledtext.ScrolledText(window, wrap=tk.WORD, width=80, height=10)
# textarea_en.pack()
# window.mainloop()
@
app
.
post
(
"/uploaded_video/v1"
)
async
def
uploaded_video
(
file
:
UploadFile
=
File
(
...
)):
try
:
# Process the uploaded video
video_content
=
await
file
.
read
()
video_io
=
io
.
BytesIO
(
video_content
)
audio_save_path
=
"audio.wav"
video
=
mp
.
VideoFileClip
(
video_io
,
codec
=
"mpeg4"
)
audio
=
video
.
audio
audio
.
write_audiofile
(
audio_save_path
)
r
=
sr
.
Recognizer
()
with
sr
.
AudioFile
(
audio_save_path
)
as
source
:
audio
=
r
.
record
(
source
)
recognized_text
=
r
.
recognize_google
(
audio
,
language
=
"si-LK"
)
translated_text_si
=
translate_text
(
recognized_text
,
"si"
)
translated_text_en
=
translate_text
(
recognized_text
,
"en"
)
translated_integer_si
=
" "
.
join
(
str
(
unicode_to_int_mapping
.
get
(
word
,
0
))
for
word
in
translated_text_si
.
split
()
)
print
(
"Translated Integer (Si):"
,
translated_integer_si
)
send_to_service
(
translated_integer_si
)
return
JSONResponse
(
content
=
{
"translated_text_si"
:
translated_text_si
,
"translated_text_en"
:
translated_text_en
,
}
)
except
Exception
as
e
:
return
JSONResponse
(
content
=
{
"error"
:
str
(
e
)},
status_code
=
500
)
Project/Backend/Server_Python/services/video_to_sign_language.py
deleted
100644 → 0
View file @
f46f5d41
import
moviepy.editor
as
mp
import
speech_recognition
as
sr
import
tkinter
as
tk
from
tkinter
import
filedialog
from
tkinter
import
messagebox
from
tkinter
import
scrolledtext
import
requests
# Define a dictionary to map Sinhala Unicode to integers
unicode_to_int_mapping
=
{
"මම"
:
1
,
"හෙට"
:
2
,
"යනවා"
:
3
,
"මං"
:
4
}
def
translate_text
(
text
,
target_language
):
url
=
"https://translate.googleapis.com/translate_a/single"
params
=
{
"client"
:
"gtx"
,
"sl"
:
"auto"
,
"tl"
:
target_language
,
"dt"
:
"t"
,
"q"
:
text
}
response
=
requests
.
get
(
url
,
params
=
params
)
translation_data
=
response
.
json
()
translated_text
=
translation_data
[
0
][
0
][
0
]
return
translated_text
def
convert_video
():
video_path
=
filedialog
.
askopenfilename
(
filetypes
=
[(
"Video Files"
,
"*.mp4"
)])
if
not
video_path
:
messagebox
.
showwarning
(
"Warning"
,
"No video file selected."
)
return
try
:
audio_save_path
=
"audio.wav"
video
=
mp
.
VideoFileClip
(
video_path
)
audio
=
video
.
audio
audio
.
write_audiofile
(
audio_save_path
)
r
=
sr
.
Recognizer
()
with
sr
.
AudioFile
(
audio_save_path
)
as
source
:
audio
=
r
.
record
(
source
)
recognized_text
=
r
.
recognize_google
(
audio
,
language
=
'si-LK'
)
translated_text_si
=
translate_text
(
recognized_text
,
"si"
)
translated_text_en
=
translate_text
(
recognized_text
,
"en"
)
# Get the integer values and join them into a single string
translated_integer_si
=
' '
.
join
(
str
(
unicode_to_int_mapping
.
get
(
word
,
0
))
for
word
in
translated_text_si
.
split
())
textarea_si
.
delete
(
'1.0'
,
tk
.
END
)
textarea_en
.
delete
(
'1.0'
,
tk
.
END
)
textarea_si
.
insert
(
tk
.
END
,
f
"Translated Integer: {translated_integer_si}
\n
{translated_text_si}"
)
textarea_en
.
insert
(
tk
.
END
,
translated_text_en
)
except
Exception
as
e
:
messagebox
.
showerror
(
"Error"
,
str
(
e
))
window
=
tk
.
Tk
()
window
.
title
(
"Video Translation"
)
window
.
geometry
(
"800x600"
)
title_label
=
tk
.
Label
(
window
,
text
=
"Video Translation"
,
font
=
(
"Arial"
,
16
,
"bold"
))
title_label
.
pack
(
pady
=
10
)
convert_button
=
tk
.
Button
(
window
,
text
=
"Convert Video"
,
command
=
convert_video
)
convert_button
.
pack
(
pady
=
10
)
textarea_si_label
=
tk
.
Label
(
window
,
text
=
"Sinhala Unicode Translation"
)
textarea_si_label
.
pack
()
textarea_si
=
scrolledtext
.
ScrolledText
(
window
,
wrap
=
tk
.
WORD
,
width
=
80
,
height
=
10
)
textarea_si
.
pack
()
textarea_en_label
=
tk
.
Label
(
window
,
text
=
"Singlish Translation"
)
textarea_en_label
.
pack
()
textarea_en
=
scrolledtext
.
ScrolledText
(
window
,
wrap
=
tk
.
WORD
,
width
=
80
,
height
=
10
)
textarea_en
.
pack
()
window
.
mainloop
()
\ No newline at end of file
Project/Frontend/SignConnectPlus/src/pages/services/VideoToSignLanguage.js
View file @
a35b6b73
...
@@ -3,7 +3,8 @@ import axios from 'axios';
...
@@ -3,7 +3,8 @@ import axios from 'axios';
class
VideoToSignLanguage
{
class
VideoToSignLanguage
{
videoTranslation
(
data
)
{
videoTranslation
(
data
)
{
return
axios
.
post
(
return
axios
.
post
(
`http://127.0.0.1:8000/predict-sign-language/video/speed_levels?speed=
${
speed
}
`
,
// @ts-ignore
`http://127.0.0.1:8000/translated_items/`
,
data
data
);
);
}
}
...
...
Project/Frontend/SignConnectPlus/src/pages/video-to-sign-language/VideoTranslate/VideoTranslate.tsx
View file @
a35b6b73
...
@@ -15,7 +15,7 @@ import {
...
@@ -15,7 +15,7 @@ import {
LinearProgress
,
LinearProgress
,
Paper
,
Paper
,
// Slider,
// Slider,
//
Stack,
Stack
,
TextField
,
TextField
,
Typography
Typography
}
from
'
@mui/material
'
;
}
from
'
@mui/material
'
;
...
@@ -23,7 +23,7 @@ import {
...
@@ -23,7 +23,7 @@ import {
import
{
useState
}
from
'
react
'
;
import
{
useState
}
from
'
react
'
;
import
{
useSnackbar
}
from
'
notistack
'
;
import
{
useSnackbar
}
from
'
notistack
'
;
import
{
MuiFileInput
}
from
'
mui-file-input
'
;
import
{
MuiFileInput
}
from
'
mui-file-input
'
;
import
{
CloudUploadOutlined
,
HighlightOutlined
,
CopyOutlined
,
TranslationOutlined
}
from
'
@ant-design/icons
'
;
import
{
CloudUploadOutlined
,
HighlightOutlined
,
CopyOutlined
,
TranslationOutlined
}
from
'
@ant-design/icons
'
;
import
VideoToSignLanguageService
from
'
../../services/VideoToSignLanguage.js
'
;
import
VideoToSignLanguageService
from
'
../../services/VideoToSignLanguage.js
'
;
// ==============================|| List ||============================== //
// ==============================|| List ||============================== //
...
@@ -33,6 +33,8 @@ const VideoTranslate = () => {
...
@@ -33,6 +33,8 @@ const VideoTranslate = () => {
const
[
videoUrl
,
setVideoUrl
]
=
useState
(
''
);
const
[
videoUrl
,
setVideoUrl
]
=
useState
(
''
);
const
[
loading
,
setLoading
]
=
useState
(
false
);
const
[
loading
,
setLoading
]
=
useState
(
false
);
const
[
value
,
setValue
]
=
useState
(
''
);
const
[
value
,
setValue
]
=
useState
(
''
);
const
[
translatedTextSi
,
setTranslatedTextSi
]
=
useState
(
''
);
const
[
translatedTextEn
,
setTranslatedTextEn
]
=
useState
(
''
);
const
handleDropSingleFile
=
(
files
:
any
)
=>
{
const
handleDropSingleFile
=
(
files
:
any
)
=>
{
if
(
files
)
{
if
(
files
)
{
...
@@ -60,13 +62,18 @@ const VideoTranslate = () => {
...
@@ -60,13 +62,18 @@ const VideoTranslate = () => {
const
formData
=
new
FormData
();
const
formData
=
new
FormData
();
//@ts-ignore
//@ts-ignore
formData
.
append
(
'
video_request
'
,
file
,
file
.
name
);
formData
.
append
(
'
video
'
,
file
,
file
.
name
);
try
{
try
{
const
response
=
await
VideoToSignLanguageService
.
videoTranslation
(
formData
);
const
response
=
await
VideoToSignLanguageService
.
videoTranslation
(
formData
);
const
{
translated_text_si
,
translated_text_en
}
=
response
.
data
;
setTranslatedTextSi
(
translated_text_si
);
setTranslatedTextEn
(
translated_text_en
);
if
(
response
.
status
==
200
)
{
if
(
response
.
status
==
200
)
{
console
.
log
(
response
.
data
);
console
.
log
(
response
.
data
);
setValue
(
response
.
data
.
predictions
);
//
setValue(response.data.predictions);
}
else
{
}
else
{
enqueueSnackbar
(
'
Something went Wrong!
'
,
{
variant
:
'
error
'
});
enqueueSnackbar
(
'
Something went Wrong!
'
,
{
variant
:
'
error
'
});
}
}
...
@@ -90,7 +97,6 @@ const VideoTranslate = () => {
...
@@ -90,7 +97,6 @@ const VideoTranslate = () => {
}
}
};
};
return
(
return
(
<
MainCard
content=
{
false
}
>
<
MainCard
content=
{
false
}
>
<
ScrollX
>
<
ScrollX
>
...
@@ -98,13 +104,40 @@ const VideoTranslate = () => {
...
@@ -98,13 +104,40 @@ const VideoTranslate = () => {
<
Container
<
Container
sx=
{
{
sx=
{
{
padding
:
2
padding
:
3
,
bgcolor
:
'
#625D5D
'
,
color
:
'
#fafafb
'
,
borderRadius
:
6
,
// boxShadow: '0px 4px 6px rgba(0, 0, 0, 0.1)' // Subtle box shadow
}
}
}
}
>
>
{
/* Double Button Here */
}
{
/* Double Button Here */
}
<
ButtonGroup
disableElevation
variant=
"contained"
aria
-
label=
"Disabled elevation buttons"
sx=
{
{
marginBottom
:
'
10px
'
}
}
>
<
ButtonGroup
disableElevation
variant=
"contained"
aria
-
label=
"Customized buttons"
sx=
{
{
marginBottom
:
'
20px
'
,
backgroundColor
:
'
#ff3c3c
'
,
// Change background color
'
& .MuiButton-root
'
:
{
// Apply styles to individual buttons
color
:
'
white
'
,
// Text color
'
&:hover
'
:
{
backgroundColor
:
'
#000000
'
// Change color on hover
}
}
}
}
>
<
Button
<
Button
sx=
{
{
bgcolor
:
'
#ff3c3c
'
,
padding
:
'
10px 50px
'
,
fontSize
:
'
1.05rem
'
,
// Larger font size
'
& .anticon
'
:
{
fontSize
:
'
1.2rem
'
,
// Larger icon size
},
}
}
// variant={checkTranalationTypeForUpload()}
// variant={checkTranalationTypeForUpload()}
startIcon=
{
<
CloudUploadOutlined
/>
}
startIcon=
{
<
CloudUploadOutlined
/>
}
// onClick={() => {
// onClick={() => {
...
@@ -115,6 +148,14 @@ const VideoTranslate = () => {
...
@@ -115,6 +148,14 @@ const VideoTranslate = () => {
</
Button
>
</
Button
>
<
Button
<
Button
sx=
{
{
bgcolor
:
'
#ff3c3c
'
,
padding
:
'
10px 50px
'
,
fontSize
:
'
1.05rem
'
,
// Larger font size
'
& .anticon
'
:
{
fontSize
:
'
1.2rem
'
,
// Larger icon size
},
}
}
// variant={checkTranalationTypeForRecord()}
// variant={checkTranalationTypeForRecord()}
startIcon=
{
<
HighlightOutlined
/>
}
startIcon=
{
<
HighlightOutlined
/>
}
// onClick={() => {
// onClick={() => {
...
@@ -128,18 +169,16 @@ const VideoTranslate = () => {
...
@@ -128,18 +169,16 @@ const VideoTranslate = () => {
{
/* Video uploading */
}
{
/* Video uploading */
}
<
Box
sx=
{
{
flexGrow
:
1
}
}
>
<
Box
sx=
{
{
flexGrow
:
1
}
}
>
<
Card
>
<
Card
>
<
CardHeader
title=
"Upload a video
containing Sign Languag
e"
/>
<
CardHeader
title=
"Upload a video
| Drag & Drop or Select Fil
e"
/>
<
Grid
container
spacing=
{
2
}
>
<
Grid
container
spacing=
{
2
}
>
<
Grid
item
xs=
{
12
}
md=
{
6
}
>
<
Grid
item
xs=
{
12
}
md=
{
6
}
>
<
Card
sx=
{
{
marginBottom
:
'
10px
'
,
marginLeft
:
'
10px
'
}
}
>
<
Card
sx=
{
{
marginBottom
:
'
20px
'
,
marginLeft
:
'
10px
'
,
padding
:
'
35px
10px
'
}
}
>
<
CardContent
>
<
CardContent
>
{
/* ! Important */
}
{
/* ! Important */
}
{
/* @ts-ignore */
}
{
/* @ts-ignore */
}
<
MuiFileInput
value=
{
file
}
onChange=
{
handleDropSingleFile
}
inputProps=
{
{
accept
:
'
video/*
'
}
}
/>
<
MuiFileInput
value=
{
file
}
onChange=
{
handleDropSingleFile
}
inputProps=
{
{
accept
:
'
video/*
'
}
}
/>
<
Paper
style=
{
{
padding
:
'
20px
'
,
marginTop
:
'
15px
'
}
}
>
<
Paper
style=
{
{
padding
:
'
20px
'
,
marginTop
:
'
15px
'
}
}
>
<
Typography
variant=
"h5"
align=
"center"
gutterBottom
>
<
Typography
variant=
"h5"
align=
"center"
gutterBottom
>
Preview
Preview
...
@@ -151,15 +190,15 @@ const VideoTranslate = () => {
...
@@ -151,15 +190,15 @@ const VideoTranslate = () => {
</
CardContent
>
</
CardContent
>
</
Card
>
</
Card
>
</
Grid
>
</
Grid
>
{
/*
<Grid item xs={12} md={6}>
<
Grid
item
xs=
{
12
}
md=
{
6
}
>
<
Card
sx=
{
{
p
:
5
,
minHeight
:
300
,
marginBottom
:
'
10px
'
,
marginRight
:
'
10px
'
}
}
>
<
Card
sx=
{
{
p
:
5
,
minHeight
:
300
,
marginBottom
:
'
10px
'
,
marginRight
:
'
10px
'
}
}
>
<
Box
display=
"grid"
gap=
{
5
}
>
<
Box
display=
"grid"
gap=
{
5
}
>
<
Stack
spacing=
{
2
}
>
<
Stack
spacing=
{
2
}
>
<Grid container spacing={
2
}>
<
Grid
container
spacing=
{
1
}
>
<Grid item xs={12} md={6}>
{
/* <Grid item xs={12} md={6}> */
}
<h3>Set Sign Speed </h3>
{
/* <h3>Set Sign Speed </h3> */
}
<Slider
{
/*
<Slider
defaultValue={30}
defaultValue={30}
getAriaValueText={valuetext}
getAriaValueText={valuetext}
valueLabelDisplay="auto"
valueLabelDisplay="auto"
...
@@ -167,10 +206,10 @@ const VideoTranslate = () => {
...
@@ -167,10 +206,10 @@ const VideoTranslate = () => {
marks
marks
min={10}
min={10}
max={110}
max={110}
/>
/>
*/
}
<h4>Speed - {speed}</h4>
{
/* <h4>Speed - {speed}</h4> */
}
</Grid> */
}
{
/*
</Grid> */
}
<
Grid
item
xs=
{
12
}
md=
{
6
}
container
direction=
"row"
justifyContent=
"flex-
end
"
alignItems=
"center"
>
<
Grid
item
xs=
{
12
}
md=
{
6
}
container
direction=
"row"
justifyContent=
"flex-
start
"
alignItems=
"center"
>
<
Button
<
Button
variant=
"contained"
variant=
"contained"
style=
{
{
width
:
'
200px
'
,
height
:
'
60px
'
,
fontSize
:
'
20px
'
}
}
style=
{
{
width
:
'
200px
'
,
height
:
'
60px
'
,
fontSize
:
'
20px
'
}
}
...
@@ -178,9 +217,7 @@ const VideoTranslate = () => {
...
@@ -178,9 +217,7 @@ const VideoTranslate = () => {
mb
:
3
mb
:
3
}
}
}
}
disabled=
{
loading
}
disabled=
{
loading
}
onClick=
{
()
=>
{
onClick=
{
TranslateVideoToSignLanguage
}
TranslateVideoToSignLanguage
();
}
}
endIcon=
{
<
TranslationOutlined
/>
}
endIcon=
{
<
TranslationOutlined
/>
}
>
>
Translate
Translate
...
@@ -200,13 +237,50 @@ const VideoTranslate = () => {
...
@@ -200,13 +237,50 @@ const VideoTranslate = () => {
</
Card
>
</
Card
>
)
:
(
)
:
(
<
div
>
<
div
>
<
Typography
variant=
"overline"
sx=
{
{
color
:
'
text.secondary
'
}
}
>
Translated Text
{
/* -------- Translated Avatar ------------------------- */
}
<
Typography
variant=
"overline"
sx=
{
{
color
:
'
text.secondary
'
,
marginBottom
:
2
}
}
>
Translated Avatar
</
Typography
>
<
Paper
elevation=
{
3
}
sx=
{
{
p
:
2
,
maxWidth
:
600
,
margin
:
'
0 auto
'
,
marginBottom
:
3
}
}
>
<
video
controls
width=
"100%"
height=
"auto"
>
{
/* <source src="your-video-url.mp4" type="video/mp4" /> */
}
Your browser does not support the video tag.
</
video
>
</
Paper
>
{
/* -------- Translated Sinhala Unicode ------------------------- */
}
<
Typography
variant=
"overline"
sx=
{
{
color
:
'
text.secondary
'
,
fontStyle
:
'
italic
'
,
marginBottom
:
2
}
}
>
Sinhala Unicode
</
Typography
>
<
TextField
sx=
{
{
marginBottom
:
2
}
}
fullWidth
value=
{
translatedTextSi
}
onChange=
{
handleChange
}
InputProps=
{
{
endAdornment
:
(
<
InputAdornment
position=
"end"
>
<
IconButton
onClick=
{
()
=>
onCopy
(
value
)
}
>
<
CopyOutlined
/>
</
IconButton
>
</
InputAdornment
>
)
}
}
/>
{
/* -------- Translated English Unicode ------------------------- */
}
<
Typography
variant=
"overline"
sx=
{
{
color
:
'
text.secondary
'
,
fontStyle
:
'
italic
'
}
}
>
English Unicode
</
Typography
>
</
Typography
>
<
TextField
<
TextField
fullWidth
fullWidth
value=
{
value
}
value=
{
translatedTextEn
}
onChange=
{
handleChange
}
onChange=
{
handleChange
}
InputProps=
{
{
InputProps=
{
{
endAdornment
:
(
endAdornment
:
(
...
@@ -220,6 +294,11 @@ const VideoTranslate = () => {
...
@@ -220,6 +294,11 @@ const VideoTranslate = () => {
/>
/>
</
div
>
</
div
>
)
}
)
}
</
Stack
>
</
Box
>
</
Card
>
</
Grid
>
</
Grid
>
</
Card
>
</
Card
>
</
Box
>
</
Box
>
</
Container
>
</
Container
>
...
...
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