Merged in actually-save (pull request #6)

Actually save questions.
This commit is contained in:
Cristiano Ferreira
2023-11-28 11:11:42 +00:00
committed by Tiago Ribeiro
2 changed files with 27 additions and 38 deletions

57
app.py
View File

@@ -166,15 +166,13 @@ def save_listening():
conversation_text_to_speech(part["text"]["conversation"], sound_file_path)
else:
text_to_speech(part["text"], sound_file_path)
# file_url = upload_file_firebase_get_url(FIREBASE_BUCKET, firebase_file_path, sound_file_path)
file_url = "test_url/" + firebase_file_path
file_url = upload_file_firebase_get_url(FIREBASE_BUCKET, firebase_file_path, sound_file_path)
template["parts"][i]["audio"]["source"] = file_url
template["parts"][i]["exercises"].append(part["exercises"])
# if save_to_db("listening", template):
# return template
# else:
# raise Exception("Failed to save question: " + parts)
return template
if save_to_db("listening", template):
return template
else:
raise Exception("Failed to save question: " + parts)
except Exception as e:
return str(e)
@@ -281,11 +279,10 @@ def save_writing_task():
template = getWritingTemplate()
for i, exercise in enumerate(exercises, start=0):
template["exercises"][i]["prompt"] = exercise
# if save_to_db("writing", template):
# return template
# else:
# raise Exception("Failed to save writing: " + template)
return template
if save_to_db("writing", template):
return template
else:
raise Exception("Failed to save writing: " + template)
except Exception as e:
return str(e)
@@ -459,13 +456,11 @@ def save_speaking():
template = getSpeakingTemplate()
# Speaking 1
# sp1_result = create_video(exercises[0]["question"], random.choice(list(AvatarEnum)))
sp1_result = "speaking_1"
sp1_result = create_video(exercises[0]["question"], random.choice(list(AvatarEnum)))
if sp1_result is not None:
sound_file_path = VIDEO_FILES_PATH + sp1_result
firebase_file_path = FIREBASE_SPEAKING_VIDEO_FILES_PATH + sp1_result
# url = upload_file_firebase_get_url(FIREBASE_BUCKET, firebase_file_path, sound_file_path)
url = "speaking_1_url"
url = upload_file_firebase_get_url(FIREBASE_BUCKET, firebase_file_path, sound_file_path)
sp1_video_path = firebase_file_path
sp1_video_url = url
template["exercises"][0]["text"] = exercises[0]["question"]
@@ -476,13 +471,11 @@ def save_speaking():
print("Failed to create video for part 1 question: " + exercises[0]["question"])
# Speaking 2
# sp2_result = create_video(exercises[1]["question"], random.choice(list(AvatarEnum)))
sp2_result = "speaking_2"
sp2_result = create_video(exercises[1]["question"], random.choice(list(AvatarEnum)))
if sp2_result is not None:
sound_file_path = VIDEO_FILES_PATH + sp2_result
firebase_file_path = FIREBASE_SPEAKING_VIDEO_FILES_PATH + sp2_result
# url = upload_file_firebase_get_url(FIREBASE_BUCKET, firebase_file_path, sound_file_path)
url = "speaking_2_url"
url = upload_file_firebase_get_url(FIREBASE_BUCKET, firebase_file_path, sound_file_path)
sp2_video_path = firebase_file_path
sp2_video_url = url
template["exercises"][1]["prompts"] = exercises[1]["prompts"]
@@ -497,13 +490,11 @@ def save_speaking():
sp3_questions = []
avatar = random.choice(list(AvatarEnum))
for question in exercises[2]["questions"]:
# result = create_video(question, avatar)
result = "speaking_3"
result = create_video(question, avatar)
if result is not None:
sound_file_path = VIDEO_FILES_PATH + result
firebase_file_path = FIREBASE_SPEAKING_VIDEO_FILES_PATH + result
# url = upload_file_firebase_get_url(FIREBASE_BUCKET, firebase_file_path, sound_file_path)
url = "speaking_3_url"
url = upload_file_firebase_get_url(FIREBASE_BUCKET, firebase_file_path, sound_file_path)
video = {
"text": question,
"video_path": firebase_file_path,
@@ -515,11 +506,10 @@ def save_speaking():
template["exercises"][2]["prompts"] = sp3_questions
template["exercises"][2]["title"] = exercises[2]["topic"]
# if save_to_db("speaking", template):
# return template
# else:
# raise Exception("Failed to save speaking: " + template)
return template
if save_to_db("speaking", template):
return template
else:
raise Exception("Failed to save speaking: " + template)
except Exception as e:
return str(e)
@@ -615,11 +605,10 @@ def save_reading_passage():
parts = data.get('parts')
template = getReadingTemplate()
template["parts"] = parts
# if save_to_db("reading", template):
# return template
# else:
# raise Exception("Failed to save reading: " + template)
return template
if save_to_db("reading", template):
return template
else:
raise Exception("Failed to save reading: " + template)
except Exception as e:
return str(e)

View File

@@ -33,7 +33,7 @@ def getListeningTemplate():
"exercises": []
},
],
"isDiagnostic": True,
"isDiagnostic": False,
"minTimer": 30,
"module": "listening"
}
@@ -715,7 +715,7 @@ def getListeningPostSample():
def getReadingTemplate():
return {
"parts": [],
"isDiagnostic": True,
"isDiagnostic": False,
"minTimer": 60,
"type": "academic"
}
@@ -1179,7 +1179,7 @@ def getSpeakingTemplate():
"type": "interactiveSpeaking"
}
],
"isDiagnostic": True,
"isDiagnostic": False,
"minTimer": 14,
"module": "speaking"
}
@@ -1241,7 +1241,7 @@ def getWritingTemplate():
}
}
],
"isDiagnostic": True,
"isDiagnostic": False,
"minTimer": 60,
"module": "writing",
"type": "general"