Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
22_23-J 18
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
1
Merge Requests
1
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
22_23-J 18
22_23-J 18
Commits
2b0781aa
Commit
2b0781aa
authored
Feb 09, 2024
by
ParamiLelkada
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
new mongo creds
parent
823c9ce0
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
23 additions
and
4 deletions
+23
-4
App/Backend/__pycache__/content_filter_azure.cpython-310.pyc
App/Backend/__pycache__/content_filter_azure.cpython-310.pyc
+0
-0
App/Backend/__pycache__/flip_card_content.cpython-310.pyc
App/Backend/__pycache__/flip_card_content.cpython-310.pyc
+0
-0
App/Backend/__pycache__/word_card_game.cpython-310.pyc
App/Backend/__pycache__/word_card_game.cpython-310.pyc
+0
-0
App/Backend/__pycache__/word_generation.cpython-310.pyc
App/Backend/__pycache__/word_generation.cpython-310.pyc
+0
-0
App/Backend/requirements.txt
App/Backend/requirements.txt
+2
-1
App/Backend/word_card_game.py
App/Backend/word_card_game.py
+1
-1
App/Backend/word_generation.py
App/Backend/word_generation.py
+20
-2
No files found.
App/Backend/__pycache__/content_filter_azure.cpython-310.pyc
0 → 100644
View file @
2b0781aa
File added
App/Backend/__pycache__/flip_card_content.cpython-310.pyc
0 → 100644
View file @
2b0781aa
File added
App/Backend/__pycache__/word_card_game.cpython-310.pyc
0 → 100644
View file @
2b0781aa
File added
App/Backend/__pycache__/word_generation.cpython-310.pyc
0 → 100644
View file @
2b0781aa
File added
App/Backend/requirements.txt
View file @
2b0781aa
...
...
@@ -3,4 +3,5 @@ numpy==1.24.2
transformers
torch
pymongo
requests
\ No newline at end of file
requests
gtts
App/Backend/word_card_game.py
View file @
2b0781aa
import
random
import
pymongo
client
=
pymongo
.
MongoClient
(
"mongodb+srv://
hearme:hearme678@cluster0.kz66vdr.mongodb.net
"
)
client
=
pymongo
.
MongoClient
(
"mongodb+srv://
user123:hhCsLKxVQoWDsO2M@hearme.5yquvxf.mongodb.net/
"
)
db
=
client
[
'word_card'
]
collection
=
db
[
'card'
]
...
...
App/Backend/word_generation.py
View file @
2b0781aa
...
...
@@ -2,11 +2,29 @@ import torch
from
transformers
import
RobertaTokenizer
,
RobertaForMaskedLM
import
pymongo
from
content_filter_azure
import
is_word_safe
from
gtts
import
gTTS
import
os
# Load the pretrained RoBERTa model and tokenizer
tokenizer
=
RobertaTokenizer
.
from_pretrained
(
'roberta-base'
)
model
=
RobertaForMaskedLM
.
from_pretrained
(
'roberta-base'
)
def
generate_audio_save_locally
(
word
):
# Define the path where you want to save the audio file
# Using a temporary directory or a specific path
temp_dir
=
"./temp_audio"
os
.
makedirs
(
temp_dir
,
exist_ok
=
True
)
# Ensure the directory exists
# Define the full path for the audio file
file_path
=
os
.
path
.
join
(
temp_dir
,
f
"{word}.mp3"
)
# Generate the audio using gTTS
tts
=
gTTS
(
text
=
word
,
lang
=
'en'
)
tts
.
save
(
file_path
)
# Return the local path of the generated audio file
return
file_path
def
get_similar_words
(
input_word
,
top_k
=
3
):
# Create a masked sentence with the input word
masked_sentence
=
f
"The {input_word} is related to the {tokenizer.mask_token}."
...
...
@@ -35,7 +53,7 @@ def get_similar_words(input_word, top_k=3):
result
=
[]
for
word
in
related_words
:
image_url
=
f
'https://fyp-word-images.s3.us-east-2.amazonaws.com/{word}.png'
audio_url
=
f
'https://fyp-word-audio.s3.us-east-2.amazonaws.com/{word}.m4a'
audio_url
=
generate_audio_save_locally
(
word
)
result
.
append
({
'word'
:
word
,
'image'
:
image_url
,
...
...
@@ -44,7 +62,7 @@ def get_similar_words(input_word, top_k=3):
#connect mongo
client
=
pymongo
.
MongoClient
(
"mongodb+srv://
hearme:hearme678@cluster0.kz66vdr.mongodb.net
"
)
client
=
pymongo
.
MongoClient
(
"mongodb+srv://
user123:hhCsLKxVQoWDsO2M@hearme.5yquvxf.mongodb.net/
"
)
db
=
client
[
'word_card'
]
collection
=
db
[
'card'
]
...
...
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