Update video generation to use heygen.
This commit is contained in:
@@ -48,7 +48,7 @@ class DependencyInjector:
|
|||||||
elai_conf = json.load(file)
|
elai_conf = json.load(file)
|
||||||
|
|
||||||
self._container.vid_gen = providers.Factory(
|
self._container.vid_gen = providers.Factory(
|
||||||
ELAI, client=self._container.http_client, token=os.getenv("ELAI_TOKEN"), conf=elai_conf
|
Heygen, client=self._container.http_client, token=os.getenv("HEY_GEN_TOKEN")
|
||||||
)
|
)
|
||||||
self._container.ai_detector = providers.Factory(
|
self._container.ai_detector = providers.Factory(
|
||||||
GPTZero, client=self._container.http_client, gpt_zero_key=os.getenv("GPT_ZERO_API_KEY")
|
GPTZero, client=self._container.http_client, gpt_zero_key=os.getenv("GPT_ZERO_API_KEY")
|
||||||
|
|||||||
@@ -417,14 +417,14 @@ class SpeakingService(ISpeakingService):
|
|||||||
return response["fixed_text"]
|
return response["fixed_text"]
|
||||||
|
|
||||||
async def create_videos_and_save_to_db(self, exercises, template, req_id):
|
async def create_videos_and_save_to_db(self, exercises, template, req_id):
|
||||||
template = await self._create_video_per_part(exercises, template, 1)
|
template = await self._create_video_per_part(exercises, template, 1, req_id)
|
||||||
template = await self._create_video_per_part(exercises, template, 2)
|
template = await self._create_video_per_part(exercises, template, 2, req_id)
|
||||||
template = await self._create_video_per_part(exercises, template, 3)
|
template = await self._create_video_per_part(exercises, template, 3, req_id)
|
||||||
|
|
||||||
await self._document_store.save_to_db_with_id("speaking", template, req_id)
|
await self._document_store.save_to_db_with_id("speaking", template, req_id)
|
||||||
self._logger.info(f'Saved speaking to DB with id {req_id} : {str(template)}')
|
self._logger.info(f'Saved speaking to DB with id {req_id} : {str(template)}')
|
||||||
|
|
||||||
async def _create_video_per_part(self, exercises: List[Dict], template: Dict, part: int):
|
async def _create_video_per_part(self, exercises: List[Dict], template: Dict, part: int, req_id: str):
|
||||||
avatar = (random.choice(list(ELAIAvatars))).name
|
avatar = (random.choice(list(ELAIAvatars))).name
|
||||||
template_index = part - 1
|
template_index = part - 1
|
||||||
|
|
||||||
@@ -441,7 +441,8 @@ class SpeakingService(ISpeakingService):
|
|||||||
result = await self._create_video(
|
result = await self._create_video(
|
||||||
question,
|
question,
|
||||||
avatar,
|
avatar,
|
||||||
f'Failed to create video for part {part} question: {str(exercise["question"])}'
|
f'Failed to create video for part {part} question: {str(exercise["question"])}',
|
||||||
|
req_id
|
||||||
)
|
)
|
||||||
if result is not None:
|
if result is not None:
|
||||||
video = {
|
video = {
|
||||||
@@ -588,8 +589,8 @@ class SpeakingService(ISpeakingService):
|
|||||||
response["id"] = str(uuid.uuid4())
|
response["id"] = str(uuid.uuid4())
|
||||||
return response
|
return response
|
||||||
|
|
||||||
async def _create_video(self, question: str, avatar: str, error_message: str):
|
async def _create_video(self, question: str, avatar: str, error_message: str, title: str):
|
||||||
result = await self._vid_gen.create_video(question, avatar)
|
result = await self._vid_gen.create_video(question, avatar, title)
|
||||||
if result is not None:
|
if result is not None:
|
||||||
sound_file_path = FilePaths.VIDEO_FILES_PATH + result
|
sound_file_path = FilePaths.VIDEO_FILES_PATH + result
|
||||||
firebase_file_path = FilePaths.FIREBASE_SPEAKING_VIDEO_FILES_PATH + result
|
firebase_file_path = FilePaths.FIREBASE_SPEAKING_VIDEO_FILES_PATH + result
|
||||||
|
|||||||
@@ -26,10 +26,9 @@ class Heygen(IVideoGeneratorService):
|
|||||||
self._logger = logging.getLogger(__name__)
|
self._logger = logging.getLogger(__name__)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
async def create_video(self, text: str, avatar: str):
|
async def create_video(self, text: str, avatar: str, title="video_title": str):
|
||||||
pass
|
pass
|
||||||
# POST TO CREATE VIDEO
|
# POST TO CREATE VIDEO
|
||||||
"""
|
|
||||||
create_video_url = 'https://api.heygen.com/v2/template/' + avatar + '/generate'
|
create_video_url = 'https://api.heygen.com/v2/template/' + avatar + '/generate'
|
||||||
data = {
|
data = {
|
||||||
"test": False,
|
"test": False,
|
||||||
@@ -89,5 +88,3 @@ class Heygen(IVideoGeneratorService):
|
|||||||
else:
|
else:
|
||||||
self._logger.error(f"Failed to download file. Status code: {response.status_code}")
|
self._logger.error(f"Failed to download file. Status code: {response.status_code}")
|
||||||
return None
|
return None
|
||||||
"""
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user