Add new speaking version.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,3 +1,5 @@
|
|||||||
|
import random
|
||||||
|
|
||||||
from helper.firebase_helper import upload_file_firebase_get_url
|
from helper.firebase_helper import upload_file_firebase_get_url
|
||||||
from helper.heygen_api import create_video
|
from helper.heygen_api import create_video
|
||||||
import os
|
import os
|
||||||
@@ -21,18 +23,71 @@ FIREBASE_BUCKET = 'mti-ielts.appspot.com'
|
|||||||
VIDEO_FILES_PATH = 'download-video/'
|
VIDEO_FILES_PATH = 'download-video/'
|
||||||
FIREBASE_SPEAKING_VIDEO_FILES_PATH = 'speaking_videos/'
|
FIREBASE_SPEAKING_VIDEO_FILES_PATH = 'speaking_videos/'
|
||||||
|
|
||||||
|
# PART 1
|
||||||
|
sp1_video_url = ""
|
||||||
|
sp1_video_path = ""
|
||||||
|
|
||||||
|
# sp1_questions_json = {
|
||||||
|
# "topic": "Hobbies and Interests",
|
||||||
|
# "question": "What do you like to do in your free time? Do you have any hobbies or interests? Are there any new hobbies you would like to try in the future?"
|
||||||
|
# }
|
||||||
|
sp1_questions_json = {
|
||||||
|
"topic": "Hobbies and Interests",
|
||||||
|
"question": "Do you have any hobbies or interests that you enjoy in your free time? Please describe one of your favorite hobbies and explain why you like it."
|
||||||
|
}
|
||||||
|
|
||||||
|
sp1_result = create_video(sp1_questions_json["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
|
||||||
|
else:
|
||||||
|
print("Failed to create video for question: " + sp1_questions_json["question"])
|
||||||
|
|
||||||
|
# PART 2
|
||||||
|
sp2_video_url = ""
|
||||||
|
sp2_video_path = ""
|
||||||
|
|
||||||
|
# sp2_questions_json = {
|
||||||
|
# "topic": "New Environment",
|
||||||
|
# "question": "Describe an occasion when you had to adapt to a new environment."
|
||||||
|
# }
|
||||||
|
|
||||||
|
sp2_questions_json = {
|
||||||
|
"topic": "Travel and Adventure",
|
||||||
|
"question": "Describe an occasion when you had to adapt to a new environment.",
|
||||||
|
"prompts": [
|
||||||
|
"Please include details about the destination",
|
||||||
|
"What you did there",
|
||||||
|
"why this trip was memorable for you."
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
|
sp2_result = create_video(sp2_questions_json["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)
|
||||||
|
sp2_video_path = firebase_file_path
|
||||||
|
sp2_video_url = url
|
||||||
|
else:
|
||||||
|
print("Failed to create video for question: " + sp2_questions_json["question"])
|
||||||
|
|
||||||
|
# PART 3
|
||||||
# 1
|
# 1
|
||||||
# questions_json = {
|
# sp3_questions_json = {
|
||||||
# "topic": "Technology and Society",
|
# "topic": "Technology and Society",
|
||||||
# "questions": [
|
# "questions": [
|
||||||
# "How do you think technology has affected the way people communicate with each other in today's society?",
|
# "How do you think technology has affected the way people communicate with each other in today's society?",
|
||||||
# "In what ways has the use of smartphones and social media platforms changed the dynamics of personal relationships?",
|
# "In what ways has the use of smartphones and social media platforms changed the dynamics of personal relationships?",
|
||||||
# "Some argue that technology has made communication more convenient, while others worry that it has led to a decline in face-to-face interactions. What's your perspective on this matter, and how do you think it might impact future generations?"
|
# "Some argue that technology has made communication more convenient, while others worry that it has led to a decline in face-to-face interactions. What's your perspective on this matter, and how do you think it might impact future generations?"
|
||||||
# ]
|
# ]
|
||||||
# }
|
# }
|
||||||
|
|
||||||
# 2
|
# 2
|
||||||
# questions_json = {
|
# sp3_questions_json = {
|
||||||
# "topic": "Environmental Concerns",
|
# "topic": "Environmental Concerns",
|
||||||
# "questions": [
|
# "questions": [
|
||||||
# "What do you believe are the most pressing environmental issues facing the world today?",
|
# "What do you believe are the most pressing environmental issues facing the world today?",
|
||||||
@@ -42,7 +97,7 @@ FIREBASE_SPEAKING_VIDEO_FILES_PATH = 'speaking_videos/'
|
|||||||
# }
|
# }
|
||||||
|
|
||||||
# 3
|
# 3
|
||||||
# questions_json = {
|
# sp3_questions_json = {
|
||||||
# "topic": "Education and Technology",
|
# "topic": "Education and Technology",
|
||||||
# "questions": [
|
# "questions": [
|
||||||
# "How has technology impacted the way students learn in today's classrooms?",
|
# "How has technology impacted the way students learn in today's classrooms?",
|
||||||
@@ -52,26 +107,19 @@ FIREBASE_SPEAKING_VIDEO_FILES_PATH = 'speaking_videos/'
|
|||||||
# }
|
# }
|
||||||
|
|
||||||
# 4
|
# 4
|
||||||
# questions_json = {
|
sp3_questions_json = {
|
||||||
# "topic": "Cultural Diversity",
|
"topic": "Cultural Diversity",
|
||||||
# "questions": [
|
|
||||||
# "How can exposure to different cultures benefit individuals and society as a whole?",
|
|
||||||
# "What challenges might arise in culturally diverse communities, and how can they be addressed?",
|
|
||||||
# "Do you think it's important for schools to incorporate cultural diversity into their curriculum? Why or why not?"
|
|
||||||
# ]
|
|
||||||
# }
|
|
||||||
|
|
||||||
# 5
|
|
||||||
questions_json = {
|
|
||||||
"topic": "Hobbies and Interests",
|
|
||||||
"questions": [
|
"questions": [
|
||||||
"What do you like to do in your free time? Do you have any hobbies or interests? Are there any new hobbies you would like to try in the future?",
|
"How can exposure to different cultures benefit individuals and society as a whole?",
|
||||||
|
"What challenges might arise in culturally diverse communities, and how can they be addressed?",
|
||||||
|
"Do you think it's important for schools to incorporate cultural diversity into their curriculum? Why or why not?"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
questions = []
|
questions = []
|
||||||
for question in questions_json["questions"]:
|
avatar = random.choice(list(AvatarEnum))
|
||||||
result = create_video(question, AvatarEnum.MATTHEW_NOAH)
|
for question in sp3_questions_json["questions"]:
|
||||||
|
result = create_video(question, avatar)
|
||||||
if result is not None:
|
if result is not None:
|
||||||
sound_file_path = VIDEO_FILES_PATH + result
|
sound_file_path = VIDEO_FILES_PATH + result
|
||||||
firebase_file_path = FIREBASE_SPEAKING_VIDEO_FILES_PATH + result
|
firebase_file_path = FIREBASE_SPEAKING_VIDEO_FILES_PATH + result
|
||||||
@@ -85,18 +133,37 @@ for question in questions_json["questions"]:
|
|||||||
else:
|
else:
|
||||||
print("Failed to create video for question: " + question)
|
print("Failed to create video for question: " + question)
|
||||||
|
|
||||||
if len(questions) == len(questions_json["questions"]):
|
# BUILD OBJECT TO SAVE
|
||||||
speaking_pt3_to_insert = {
|
if len(questions) == len(sp3_questions_json["questions"]):
|
||||||
|
speaking_module_to_insert = {
|
||||||
"exercises": [
|
"exercises": [
|
||||||
|
{
|
||||||
|
"id": str(uuid.uuid4()),
|
||||||
|
"prompts": [],
|
||||||
|
"text": sp1_questions_json["question"],
|
||||||
|
"title": sp1_questions_json["topic"],
|
||||||
|
"video_url": sp1_video_url,
|
||||||
|
"video_path": sp1_video_path,
|
||||||
|
"type": "speaking"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": str(uuid.uuid4()),
|
||||||
|
"prompts": sp2_questions_json["prompts"],
|
||||||
|
"text": sp2_questions_json["question"],
|
||||||
|
"title": sp2_questions_json["topic"],
|
||||||
|
"video_url": sp2_video_url,
|
||||||
|
"video_path": sp2_video_path,
|
||||||
|
"type": "speaking"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"id": str(uuid.uuid4()),
|
"id": str(uuid.uuid4()),
|
||||||
"prompts": questions,
|
"prompts": questions,
|
||||||
"text": "Listen carefully and respond.",
|
"text": "Listen carefully and respond.",
|
||||||
"title": questions_json["topic"],
|
"title": sp3_questions_json["topic"],
|
||||||
"type": "interactiveSpeaking"
|
"type": "interactiveSpeaking"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"isDiagnostic": False,
|
"isDiagnostic": True,
|
||||||
"minTimer": 14,
|
"minTimer": 14,
|
||||||
"module": "speaking"
|
"module": "speaking"
|
||||||
}
|
}
|
||||||
@@ -107,7 +174,7 @@ if len(questions) == len(questions_json["questions"]):
|
|||||||
|
|
||||||
# Add the JSON data to Firestore
|
# Add the JSON data to Firestore
|
||||||
collection_ref = db.collection('speaking')
|
collection_ref = db.collection('speaking')
|
||||||
document_ref = collection_ref.add(speaking_pt3_to_insert)
|
document_ref = collection_ref.add(speaking_module_to_insert)
|
||||||
print(f"Document added with ID: {document_ref}")
|
print(f"Document added with ID: {document_ref}")
|
||||||
else:
|
else:
|
||||||
print("Array sizes do not match. Video uploading failing is probably the cause.")
|
print("Array sizes do not match. Video uploading failing is probably the cause.")
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ TYLER_CHRISTOPHER = "03c796f8ed274bb38f19e893bcbc6121"
|
|||||||
def create_video(text, avatar: AvatarEnum):
|
def create_video(text, avatar: AvatarEnum):
|
||||||
# POST TO CREATE VIDEO
|
# POST TO CREATE VIDEO
|
||||||
data = {
|
data = {
|
||||||
"template_id": avatar,
|
"template_id": avatar.value,
|
||||||
"title": "video_title",
|
"title": "video_title",
|
||||||
"test": False,
|
"test": False,
|
||||||
"variables": [
|
"variables": [
|
||||||
|
|||||||
Reference in New Issue
Block a user