Update video generation to generate from template.

This commit is contained in:
Cristiano Ferreira
2023-09-25 22:37:55 +01:00
parent 035939e9a7
commit e7eb7c96ba
3 changed files with 71 additions and 26 deletions

2
.env
View File

@@ -2,4 +2,4 @@ OPENAI_API_KEY=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
JWT_SECRET_KEY=6e9c124ba92e8814719dcb0f21200c8aa4d0f119a994ac5e06eb90a366c83ab2 JWT_SECRET_KEY=6e9c124ba92e8814719dcb0f21200c8aa4d0f119a994ac5e06eb90a366c83ab2
JWT_TEST_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0In0.Emrs2D3BmMP4b3zMjw0fJTPeyMwWEBDbxx2vvaWguO0 JWT_TEST_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0In0.Emrs2D3BmMP4b3zMjw0fJTPeyMwWEBDbxx2vvaWguO0
GOOGLE_APPLICATION_CREDENTIALS=firebase-configs/mti-ielts-626a2dcf6091.json GOOGLE_APPLICATION_CREDENTIALS=firebase-configs/mti-ielts-626a2dcf6091.json
HEY_GEN_TOKEN=NTY0Y2JlY2Q4NWE4NDdhY2E4NTNhMDMwNjQ5ZDcxOGUtMTY5MzUxMjIxMw== HEY_GEN_TOKEN=MjY4MDE0MjdjZmNhNDFmYTlhZGRkNmI3MGFlMzYwZDItMTY5NTExNzY3MA==

View File

@@ -19,14 +19,56 @@ 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/'
# 1
# questions_json = {
# "topic": "Technology and Society",
# "questions": [
# "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?",
# "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
# questions_json = {
# "topic": "Environmental Concerns",
# "questions": [
# "What do you believe are the most pressing environmental issues facing the world today?",
# "In your opinion, what role should governments play in addressing environmental concerns?",
# "Many people argue that individual actions, like recycling and conserving energy, are not sufficient to address environmental issues. What's your perspective on this? How can individuals contribute to solving these problems?"
# ]
# }
# 3
# questions_json = {
# "topic": "Education and Technology",
# "questions": [
# "How has technology impacted the way students learn in today's classrooms?",
# "Do you think traditional textbooks will become obsolete in the future due to digital learning materials? Why or why not?",
# "What are the potential advantages and disadvantages of online courses and e-learning platforms?"
# ]
# }
# 4
# questions_json = {
# "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 = { questions_json = {
"topic": "Technology and Society", "topic": "Health and Lifestyle",
"questions": [ "questions": [
"How do you think technology has affected the way people communicate with each other in today's society?", "What are some of the key factors that contribute to a healthy lifestyle?",
"In what ways has the use of smartphones and social media platforms changed the dynamics of personal relationships?", "In what ways can technology help individuals monitor and improve their health?",
"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?" "How has the concept of a 'healthy lifestyle' evolved in recent years, and what role does society play in promoting it?"
] ]
} }
questions = [] questions = []
for question in questions_json["questions"]: for question in questions_json["questions"]:
result = create_video(question) result = create_video(question)
@@ -51,11 +93,11 @@ if len(questions) == len(questions_json["questions"]):
"prompts": questions, "prompts": questions,
"text": "Listen carefully and respond.", "text": "Listen carefully and respond.",
"title": questions_json["topic"], "title": questions_json["topic"],
"type": "speakingPart3" "type": "interactiveSpeaking"
} }
], ],
"isDiagnostic": True, "isDiagnostic": False,
"minTimer": 5, "minTimer": 14,
"module": "speaking" "module": "speaking"
} }

View File

@@ -10,7 +10,7 @@ load_dotenv()
TOKEN = os.getenv("HEY_GEN_TOKEN") TOKEN = os.getenv("HEY_GEN_TOKEN")
# POST TO CREATE VIDEO # POST TO CREATE VIDEO
CREATE_VIDEO_URL = 'https://api.heygen.com/v1/video.generate' CREATE_VIDEO_URL = 'https://api.heygen.com/v1/template.generate'
GET_VIDEO_URL = 'https://api.heygen.com/v1/video_status.get' GET_VIDEO_URL = 'https://api.heygen.com/v1/video_status.get'
POST_HEADER = { POST_HEADER = {
'X-Api-Key': TOKEN, 'X-Api-Key': TOKEN,
@@ -20,26 +20,29 @@ GET_HEADER = {
'X-Api-Key': TOKEN 'X-Api-Key': TOKEN
} }
MATTHEW_NOAH = "11b234e504e44bfda9bc6b7aac3c8f81"
VERA_CERISE = "9bf2f27009cd403ab4ba4e22629b27bb"
EDWARD_TONY = "d3333e37952946059b45efc8482a2b6c"
TANYA_MOLLY = "07c75076b3f94df4ac658c6de72be83a"
KAYLA_ABBI = "d688099f8db9472cb4890b0561e81793"
JEROME_RYAN = "ad41feb2a5c4483085525e3d8907f512"
TYLER_CHRISTOPHER = "03c796f8ed274bb38f19e893bcbc6121"
def create_video(text): def create_video(text):
# POST TO CREATE VIDEO # POST TO CREATE VIDEO
data = { data = {
"background": "#ffffff", "template_id": MATTHEW_NOAH,
"clips": [ "title": "video_title",
"test": False,
"variables": [
{ {
"avatar_id": "Mido-lite-20221128", "properties": {
"avatar_style": "normal", "text": text
"input_text": text,
"offset": {
"x": 0,
"y": 0
}, },
"scale": 1, "name": "avatar_0"
"voice_id": "ccb30e87c6b34ca8941f88352c71612d"
} }
], ]
"ratio": "16:9",
"test": True,
"version": "v1alpha"
} }
response = requests.post(CREATE_VIDEO_URL, headers=POST_HEADER, json=data) response = requests.post(CREATE_VIDEO_URL, headers=POST_HEADER, json=data)
print(response.status_code) print(response.status_code)
@@ -84,4 +87,4 @@ def create_video(text):
return output_filename return output_filename
else: else:
print(f"Failed to download file. Status code: {response.status_code}") print(f"Failed to download file. Status code: {response.status_code}")
return None return None