Added two more endpoints for the Speaking generation
This commit is contained in:
68
app.py
68
app.py
@@ -9,7 +9,8 @@ from helper.api_messages import *
|
||||
from helper.exercises import *
|
||||
from helper.file_helper import delete_files_older_than_one_day
|
||||
from helper.firebase_helper import *
|
||||
from helper.heygen_api import create_videos_and_save_to_db
|
||||
from helper.heygen_api import create_video, create_videos_and_save_to_db
|
||||
from heygen.AvatarEnum import AvatarEnum
|
||||
from helper.speech_to_text_helper import *
|
||||
from helper.openai_interface import *
|
||||
import os
|
||||
@@ -563,9 +564,9 @@ def save_speaking():
|
||||
exercises = data.get('exercises')
|
||||
minTimer = data.get('minTimer', SPEAKING_MIN_TIMER_DEFAULT)
|
||||
template = getSpeakingTemplate()
|
||||
template["minTimer"] = minTimer
|
||||
|
||||
if minTimer != SPEAKING_MIN_TIMER_DEFAULT:
|
||||
template["minTimer"] = minTimer
|
||||
if minTimer < SPEAKING_MIN_TIMER_DEFAULT:
|
||||
template["variant"] = ExamVariant.PARTIAL.value
|
||||
else:
|
||||
template["variant"] = ExamVariant.FULL.value
|
||||
@@ -586,6 +587,67 @@ def save_speaking():
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
|
||||
@app.route("/speaking/generate_speaking_video", methods=['POST'])
|
||||
@jwt_required()
|
||||
def generate_speaking_video():
|
||||
try:
|
||||
data = request.get_json()
|
||||
sp1_result = create_video(data["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)
|
||||
sp1_video_path = firebase_file_path
|
||||
sp1_video_url = url
|
||||
|
||||
return {
|
||||
"text": data["question"],
|
||||
"prompts": data["prompts"],
|
||||
"title": data["topic"],
|
||||
"video_url": sp1_video_url,
|
||||
"video_path": sp1_video_path,
|
||||
"type": "speaking",
|
||||
"id": uuid.uuid4()
|
||||
}
|
||||
else:
|
||||
app.logger.error("Failed to create video for part 1 question: " + data["question"])
|
||||
return str("Failed to create video for part 1 question: " + data["question"])
|
||||
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
|
||||
@app.route("/speaking/generate_interactive_video", methods=['POST'])
|
||||
@jwt_required()
|
||||
def generate_interactive_video():
|
||||
try:
|
||||
data = request.get_json()
|
||||
sp3_questions = []
|
||||
avatar = random.choice(list(AvatarEnum))
|
||||
|
||||
app.logger.info('Creating videos for speaking part 3')
|
||||
for question in data["questions"]:
|
||||
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)
|
||||
video = {
|
||||
"text": question,
|
||||
"video_path": firebase_file_path,
|
||||
"video_url": url
|
||||
}
|
||||
sp3_questions.append(video)
|
||||
else:
|
||||
app.app.logger.error("Failed to create video for part 3 question: " + question)
|
||||
|
||||
return {
|
||||
"prompts": sp3_questions,
|
||||
"title": data["topic"],
|
||||
"type": "interactiveSpeaking",
|
||||
"id": uuid.uuid4()
|
||||
}
|
||||
except Exception as e:
|
||||
return str(e)
|
||||
|
||||
@app.route('/reading_passage_1', methods=['GET'])
|
||||
@jwt_required()
|
||||
|
||||
@@ -36,6 +36,7 @@ KAYLA_ABBI = "d688099f8db9472cb4890b0561e81793"
|
||||
JEROME_RYAN = "ad41feb2a5c4483085525e3d8907f512"
|
||||
TYLER_CHRISTOPHER = "03c796f8ed274bb38f19e893bcbc6121"
|
||||
|
||||
|
||||
def create_videos_and_save_to_db(exercises, template, id):
|
||||
# Speaking 1
|
||||
# Using list comprehension to find the element with the desired value in the 'type' field
|
||||
|
||||
Reference in New Issue
Block a user