Firestore to Mongodb
This commit is contained in:
17
app.py
17
app.py
@@ -5,6 +5,7 @@ import firebase_admin
|
||||
from firebase_admin import credentials
|
||||
from flask import Flask, request
|
||||
from flask_jwt_extended import JWTManager, jwt_required
|
||||
from pymongo import MongoClient
|
||||
from sentence_transformers import SentenceTransformer
|
||||
|
||||
from helper.api_messages import *
|
||||
@@ -44,12 +45,14 @@ embeddings = SentenceTransformer('all-MiniLM-L6-v2')
|
||||
kb = TrainingContentKnowledgeBase(embeddings)
|
||||
kb.load_indices_and_metadata()
|
||||
open_ai = GPT(OpenAI())
|
||||
firestore_client = firestore.client()
|
||||
tc_service = TrainingContentService(kb, open_ai, firestore_client)
|
||||
|
||||
mongo_db = MongoClient(os.getenv('MONGODB_URI'))[os.getenv('MONGODB_DB')]
|
||||
|
||||
tc_service = TrainingContentService(kb, open_ai, mongo_db)
|
||||
|
||||
upload_level_service = UploadLevelService(open_ai)
|
||||
|
||||
batch_users_service = BatchUsers(firestore_client)
|
||||
batch_users_service = BatchUsers(mongo_db)
|
||||
|
||||
thread_event = threading.Event()
|
||||
|
||||
@@ -157,7 +160,7 @@ def save_listening():
|
||||
else:
|
||||
template["variant"] = ExamVariant.FULL.value
|
||||
|
||||
(result, id) = save_to_db_with_id("listening", template, id)
|
||||
(result, id) = save_to_db_with_id(mongo_db, "listening", template, id)
|
||||
if result:
|
||||
return {**template, "id": id}
|
||||
else:
|
||||
@@ -967,7 +970,7 @@ def save_speaking():
|
||||
name=("thread-save-speaking-" + id)
|
||||
)
|
||||
thread.start()
|
||||
app.logger.info('Started thread to save speaking. Thread: ' + thread.getName())
|
||||
app.logger.info('Started thread to save speaking. Thread: ' + thread.name)
|
||||
|
||||
# Return response without waiting for create_videos_and_save_to_db to finish
|
||||
return {**template, "id": id}
|
||||
@@ -1197,7 +1200,7 @@ def get_reading_passage_3_question():
|
||||
def get_level_exam():
|
||||
try:
|
||||
number_of_exercises = 25
|
||||
exercises = gen_multiple_choice_level(number_of_exercises)
|
||||
exercises = gen_multiple_choice_level(mongo_db, number_of_exercises)
|
||||
return {
|
||||
"exercises": [exercises],
|
||||
"isDiagnostic": False,
|
||||
@@ -1290,7 +1293,7 @@ def get_level_utas():
|
||||
bs_2["questions"] = blank_space_text_2
|
||||
|
||||
# Reading text
|
||||
reading_text = gen_reading_passage_utas(87, 10, 4)
|
||||
reading_text = gen_reading_passage_utas(mongo_db, 87, 10, 4)
|
||||
print(json.dumps(reading_text, indent=4))
|
||||
reading["questions"] = reading_text
|
||||
|
||||
|
||||
Reference in New Issue
Block a user