Commit 356a4eb4 authored by Priyanka P D M K 's avatar Priyanka P D M K

Update app backend

parent b166a3f6
import pymongo
def getFlipCardContent():
client = pymongo.MongoClient("mongodb+srv://")
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]
X = [[Total_Points, Time_Spent]]
X = scaler.transform(X)
pred = model.predict(X)
Level = int(pred[0])
return Level
def hello_world():
return "<p>Hello, Welcome</p>"
def predictHealthCall():
point = request.args.get('TotalPoints')
time = request.args.get('time')
response = Predict_Level(point, time)
response -= 1
json_string = json.dumps({'level': response})
return json_string
if __name__ == '__main__':
......@@ -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
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
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('', port=5000, debug=True))'', 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):
#connect to mongoDB
client = pymongo.MongoClient("mongodb+srv://")
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("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://")
db_1 = client['word_card']
collection_1 = db_1['card']
db = client['word_card']
collection = db['card']
document = {"card_0": result}
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