From e7eb7c96baa2429a83598769a45672f6c8eb933b Mon Sep 17 00:00:00 2001 From: Cristiano Ferreira Date: Mon, 25 Sep 2023 22:37:55 +0100 Subject: [PATCH] Update video generation to generate from template. --- .env | 2 +- generate_speaking_questions.py | 60 +++++++++++++++++++++++++++++----- helper/heygen_api.py | 35 +++++++++++--------- 3 files changed, 71 insertions(+), 26 deletions(-) diff --git a/.env b/.env index 406decf..869bba6 100644 --- a/.env +++ b/.env @@ -2,4 +2,4 @@ OPENAI_API_KEY=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 JWT_SECRET_KEY=6e9c124ba92e8814719dcb0f21200c8aa4d0f119a994ac5e06eb90a366c83ab2 JWT_TEST_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJ0ZXN0In0.Emrs2D3BmMP4b3zMjw0fJTPeyMwWEBDbxx2vvaWguO0 GOOGLE_APPLICATION_CREDENTIALS=firebase-configs/mti-ielts-626a2dcf6091.json -HEY_GEN_TOKEN=NTY0Y2JlY2Q4NWE4NDdhY2E4NTNhMDMwNjQ5ZDcxOGUtMTY5MzUxMjIxMw== \ No newline at end of file +HEY_GEN_TOKEN=MjY4MDE0MjdjZmNhNDFmYTlhZGRkNmI3MGFlMzYwZDItMTY5NTExNzY3MA== \ No newline at end of file diff --git a/generate_speaking_questions.py b/generate_speaking_questions.py index 73a0efa..617f593 100644 --- a/generate_speaking_questions.py +++ b/generate_speaking_questions.py @@ -19,14 +19,56 @@ FIREBASE_BUCKET = 'mti-ielts.appspot.com' VIDEO_FILES_PATH = 'download-video/' 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 = { - "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?" - ] + "topic": "Health and Lifestyle", + "questions": [ + "What are some of the key factors that contribute to a healthy lifestyle?", + "In what ways can technology help individuals monitor and improve their health?", + "How has the concept of a 'healthy lifestyle' evolved in recent years, and what role does society play in promoting it?" + ] } + questions = [] for question in questions_json["questions"]: result = create_video(question) @@ -51,11 +93,11 @@ if len(questions) == len(questions_json["questions"]): "prompts": questions, "text": "Listen carefully and respond.", "title": questions_json["topic"], - "type": "speakingPart3" + "type": "interactiveSpeaking" } ], - "isDiagnostic": True, - "minTimer": 5, + "isDiagnostic": False, + "minTimer": 14, "module": "speaking" } diff --git a/helper/heygen_api.py b/helper/heygen_api.py index 3601a6a..853807d 100644 --- a/helper/heygen_api.py +++ b/helper/heygen_api.py @@ -10,7 +10,7 @@ load_dotenv() TOKEN = os.getenv("HEY_GEN_TOKEN") # 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' POST_HEADER = { 'X-Api-Key': TOKEN, @@ -20,26 +20,29 @@ GET_HEADER = { '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): # POST TO CREATE VIDEO data = { - "background": "#ffffff", - "clips": [ + "template_id": MATTHEW_NOAH, + "title": "video_title", + "test": False, + "variables": [ { - "avatar_id": "Mido-lite-20221128", - "avatar_style": "normal", - "input_text": text, - "offset": { - "x": 0, - "y": 0 + "properties": { + "text": text }, - "scale": 1, - "voice_id": "ccb30e87c6b34ca8941f88352c71612d" + "name": "avatar_0" } - ], - "ratio": "16:9", - "test": True, - "version": "v1alpha" + ] } response = requests.post(CREATE_VIDEO_URL, headers=POST_HEADER, json=data) print(response.status_code) @@ -84,4 +87,4 @@ def create_video(text): return output_filename else: print(f"Failed to download file. Status code: {response.status_code}") - return None \ No newline at end of file + return None