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
356a4eb4
Commit
356a4eb4
authored
May 16, 2023
by
Priyanka P D M K
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update app backend
parent
b166a3f6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
33 deletions
+67
-33
App/Backend/flip_card_content.py
App/Backend/flip_card_content.py
+0
-1
App/Backend/quizriver.py
App/Backend/quizriver.py
+41
-0
App/Backend/server.py
App/Backend/server.py
+20
-11
App/Backend/word_generation.py
App/Backend/word_generation.py
+6
-21
No files found.
App/Backend/flip_card_content.py
View file @
356a4eb4
import
pymongo
def
getFlipCardContent
():
client
=
pymongo
.
MongoClient
(
"mongodb+srv://hearme:hearme678@cluster0.kz66vdr.mongodb.net"
)
db
=
client
[
'word_card'
]
collection
=
db
[
'card'
]
...
...
App/Backend/quizriver.py
0 → 100644
View file @
356a4eb4
import
json
from
flask
import
Flask
,
request
import
pickle
as
pickles
app
=
Flask
(
__name__
)
def
Predict_Level
(
Total_Points
,
Time_Spent
):
open_file
=
open
(
"Model_Data.pkl"
,
"rb"
)
object_list
=
pickles
.
load
(
open_file
)
scaler
=
object_list
[
0
]
model
=
object_list
[
1
]
open_file
.
close
()
X
=
[[
Total_Points
,
Time_Spent
]]
X
=
scaler
.
transform
(
X
)
pred
=
model
.
predict
(
X
)
Level
=
int
(
pred
[
0
])
return
Level
@
app
.
route
(
"/healthCheck"
)
def
hello_world
():
return
"<p>Hello, Welcome</p>"
# http://127.0.0.1:5000/predictLevel?TotalPoints=10&time=10
@
app
.
route
(
"/predictLevel"
)
def
predictHealthCall
():
point
=
request
.
args
.
get
(
'TotalPoints'
)
time
=
request
.
args
.
get
(
'time'
)
response
=
Predict_Level
(
point
,
time
)
print
(
response
)
response
-=
1
json_string
=
json
.
dumps
({
'level'
:
response
})
return
json_string
if
__name__
==
'__main__'
:
app
.
run
(
debug
=
True
)
App/Backend/server.py
View file @
356a4eb4
...
...
@@ -6,12 +6,31 @@ from flask_cors import CORS
from
word_card_game
import
wordGameData
from
word_generation
import
get_similar_words
from
flip_card_content
import
getFlipCardContent
from
content_filtration
import
check_word_safety
app
=
Flask
(
__name__
)
#### Load pretrained models here ####
#model1 = pickle.load(open('model1.pkl','rb'))
# send a json {'exp':1.8,} as a post request to make a prediction
'''
@app.route('/api/predict',methods=['POST'])
def predict():
data = request.get_json(force=True)
prediction = model1.predict([[np.array(data['exp'])]])
output = prediction[0]
return jsonify(output)
#path to check server status
@app.route("/")
def default_get():
return "<p>HereMe Backend !</p>"
'''
@
app
.
route
(
'/api/word-game'
,
methods
=
[
'GET'
])
def
word_game_api
():
w1
=
request
.
args
.
get
(
'w1'
)
...
...
@@ -44,16 +63,6 @@ def get_images_data():
images_data
=
wordGameData
()
return
jsonify
(
images_data
)
@
app
.
route
(
'/check_word'
,
methods
=
[
'POST'
])
def
check_word
():
data
=
request
.
get_json
()
word
=
data
.
get
(
'word'
)
if
not
word
:
return
jsonify
({
"error"
:
"No word provided"
}),
400
result
=
check_word_safety
(
word
)
return
jsonify
({
"word"
:
word
,
"status"
:
result
}),
200
if
__name__
==
'__main__'
:
CORS
(
app
.
run
(
host
=
'0.0.0.0'
,
port
=
5000
,
debug
=
True
))
#app.run(host='0.0.0.0', port=5000, debug=True)
\ No newline at end of file
App/Backend/word_generation.py
View file @
356a4eb4
import
torch
from
transformers
import
RobertaTokenizer
,
RobertaForMaskedLM
import
pymongo
import
random
# Load the pretrained RoBERTa model and tokenizer
tokenizer
=
RobertaTokenizer
.
from_pretrained
(
'roberta-base'
)
model
=
RobertaForMaskedLM
.
from_pretrained
(
'roberta-base'
)
def
get_similar_words
(
input_word
,
top_k
=
3
):
print
(
input_word
)
#connect to mongoDB
client
=
pymongo
.
MongoClient
(
"mongodb+srv://hearme:hearme678@cluster0.kz66vdr.mongodb.net"
)
db_0
=
client
[
'vocabulary'
]
collection_0
=
db_0
[
'object_expore'
]
cursor
=
collection_0
.
find
()
random_word
=
collection_0
.
aggregate
([{
'$sample'
:
{
'size'
:
1
}}])
.
next
()[
'object'
]
input_word
=
random_word
.
strip
()
print
(
'---------------------------------------------------------'
)
print
(
''
)
print
(
"Input word = "
+
input_word
)
# Create a masked sentence with the input word
masked_sentence
=
f
"The {input_word} is related to the {tokenizer.mask_token}."
...
...
@@ -54,14 +39,14 @@ def get_similar_words(input_word, top_k=3):
#connect mongo
client
=
pymongo
.
MongoClient
(
"mongodb+srv://hearme:hearme678@cluster0.kz66vdr.mongodb.net"
)
db
_1
=
client
[
'word_card'
]
collection
_1
=
db_1
[
'card'
]
db
=
client
[
'word_card'
]
collection
=
db
[
'card'
]
document
=
{
"card_0"
:
result
}
#
print('---------------')
#
print(document)
print
(
'---------------'
)
print
(
document
)
collection
_1
.
delete_many
({})
collection
_1
.
insert_one
(
document
)
collection
.
delete_many
({})
collection
.
insert_one
(
document
)
return
result
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