Replace prints with proper logs.
This commit is contained in:
21
app.py
21
app.py
@@ -13,6 +13,7 @@ from helper.token_counter import count_tokens
|
||||
from helper.openai_interface import make_openai_call, make_openai_instruct_call
|
||||
import os
|
||||
import re
|
||||
import logging
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
@@ -32,6 +33,9 @@ firebase_admin.initialize_app(cred)
|
||||
|
||||
thread_event = threading.Event()
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(level=logging.DEBUG, # Set the logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
|
||||
format='%(asctime)s - %(levelname)s - %(message)s')
|
||||
|
||||
@app.route('/healthcheck', methods=['GET'])
|
||||
def healthcheck():
|
||||
@@ -54,7 +58,7 @@ def get_listening_section_1_question():
|
||||
|
||||
unprocessed_conversation, processed_conversation = generate_listening_1_conversation(topic)
|
||||
|
||||
print("Generated conversation: " + str(processed_conversation))
|
||||
logging.info("Generated conversation: " + str(processed_conversation))
|
||||
|
||||
start_id = 1
|
||||
exercises = generate_listening_conversation_exercises(unprocessed_conversation, req_exercises,
|
||||
@@ -84,7 +88,7 @@ def get_listening_section_2_question():
|
||||
|
||||
monologue = generate_listening_2_monologue(topic)
|
||||
|
||||
print("Generated monologue: " + str(monologue))
|
||||
logging.info("Generated monologue: " + str(monologue))
|
||||
start_id = 11
|
||||
exercises = generate_listening_monologue_exercises(monologue, req_exercises, number_of_exercises_q, start_id)
|
||||
return {
|
||||
@@ -111,7 +115,7 @@ def get_listening_section_3_question():
|
||||
|
||||
unprocessed_conversation, processed_conversation = generate_listening_3_conversation(topic)
|
||||
|
||||
print("Generated conversation: " + str(processed_conversation))
|
||||
logging.info("Generated conversation: " + str(processed_conversation))
|
||||
|
||||
start_id = 21
|
||||
exercises = generate_listening_conversation_exercises(unprocessed_conversation, req_exercises,
|
||||
@@ -141,7 +145,7 @@ def get_listening_section_4_question():
|
||||
|
||||
monologue = generate_listening_4_monologue(topic)
|
||||
|
||||
print("Generated monologue: " + str(monologue))
|
||||
logging.info("Generated monologue: " + str(monologue))
|
||||
start_id = 31
|
||||
exercises = generate_listening_monologue_exercises(monologue, req_exercises, number_of_exercises_q, start_id)
|
||||
return {
|
||||
@@ -528,7 +532,7 @@ def save_speaking():
|
||||
exercises = data.get('exercises')
|
||||
template = getSpeakingTemplate()
|
||||
id = str(uuid.uuid4())
|
||||
|
||||
logging.info('Received request to save speaking with id: ' + id)
|
||||
thread_event.set()
|
||||
thread = threading.Thread(
|
||||
target=create_videos_and_save_to_db,
|
||||
@@ -536,6 +540,7 @@ def save_speaking():
|
||||
name=("thread-save-speaking-" + id)
|
||||
)
|
||||
thread.start()
|
||||
logging.info('Started thread to save speaking. Thread: ' + thread.getName())
|
||||
|
||||
# Return response without waiting for create_videos_and_save_to_db to finish
|
||||
return {**template, "id": id}
|
||||
@@ -557,7 +562,7 @@ def get_reading_passage_1_question():
|
||||
number_of_exercises_q = divide_number_into_parts(TOTAL_READING_PASSAGE_1_EXERCISES, len(req_exercises))
|
||||
|
||||
passage = generate_reading_passage(QuestionType.READING_PASSAGE_1, topic)
|
||||
print("Generated passage: " + str(passage))
|
||||
logging.info("Generated passage: " + str(passage))
|
||||
start_id = 1
|
||||
exercises = generate_reading_exercises(passage["text"], req_exercises, number_of_exercises_q, start_id)
|
||||
return {
|
||||
@@ -585,7 +590,7 @@ def get_reading_passage_2_question():
|
||||
number_of_exercises_q = divide_number_into_parts(TOTAL_READING_PASSAGE_2_EXERCISES, len(req_exercises))
|
||||
|
||||
passage = generate_reading_passage(QuestionType.READING_PASSAGE_2, topic)
|
||||
print("Generated passage: " + str(passage))
|
||||
logging.info("Generated passage: " + str(passage))
|
||||
start_id = 14
|
||||
exercises = generate_reading_exercises(passage["text"], req_exercises, number_of_exercises_q, start_id)
|
||||
return {
|
||||
@@ -613,7 +618,7 @@ def get_reading_passage_3_question():
|
||||
number_of_exercises_q = divide_number_into_parts(TOTAL_READING_PASSAGE_3_EXERCISES, len(req_exercises))
|
||||
|
||||
passage = generate_reading_passage(QuestionType.READING_PASSAGE_3, topic)
|
||||
print("Generated passage: " + str(passage))
|
||||
logging.info("Generated passage: " + str(passage))
|
||||
start_id = 27
|
||||
exercises = generate_reading_exercises(passage["text"], req_exercises, number_of_exercises_q, start_id)
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user