Commit 49227995 authored by Priyanka P D M K 's avatar Priyanka P D M K

Merge branch 'it19954974/PriyankaPDMK' into 'master'

It19954974 Update App Backend

See merge request !23
parents b7e76db0 a20ec9cd
import pymongo
def getFlipCardContent():
client = pymongo.MongoClient("mongodb+srv://hearme:hearme678@cluster0.kz66vdr.mongodb.net")
db = client['word_card']
collection = db['card']
......
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)
......@@ -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
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment