From b473b30a758109d3306790bfbd9fe6a5c6043d67 Mon Sep 17 00:00:00 2001 From: Cristiano Ferreira Date: Fri, 8 Nov 2024 19:05:29 +0000 Subject: [PATCH] Fix video generation --- app/services/abc/third_parties/vid_gen.py | 2 +- app/services/impl/exam/speaking.py | 12 +++++++----- app/services/impl/third_parties/heygen.py | 9 ++++----- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/services/abc/third_parties/vid_gen.py b/app/services/abc/third_parties/vid_gen.py index 5ccaef9..35d9c87 100644 --- a/app/services/abc/third_parties/vid_gen.py +++ b/app/services/abc/third_parties/vid_gen.py @@ -4,5 +4,5 @@ from abc import ABC, abstractmethod class IVideoGeneratorService(ABC): @abstractmethod - async def create_video(self, text: str, avatar: str): + async def create_video(self, text: str, avatar: str, title: str): pass diff --git a/app/services/impl/exam/speaking.py b/app/services/impl/exam/speaking.py index 2615a50..19d92f9 100644 --- a/app/services/impl/exam/speaking.py +++ b/app/services/impl/exam/speaking.py @@ -1,17 +1,17 @@ import logging import os +import random import re import uuid -import random from typing import Dict, List, Optional -from app.repositories.abc import IFileStorage, IDocumentStore -from app.services.abc import ISpeakingService, ILLMService, IVideoGeneratorService, ISpeechToTextService from app.configs.constants import ( FieldsAndExercises, GPTModels, TemperatureSettings, ELAIAvatars, FilePaths ) from app.helpers import TextHelper +from app.repositories.abc import IFileStorage, IDocumentStore +from app.services.abc import ISpeakingService, ILLMService, IVideoGeneratorService, ISpeechToTextService class SpeakingService(ISpeakingService): @@ -462,7 +462,8 @@ class SpeakingService(ISpeakingService): result = await self._create_video( exercise["question"], 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: template["exercises"][template_index]["prompts"] = exercise["prompts"] @@ -503,7 +504,8 @@ class SpeakingService(ISpeakingService): avatar, 'POST - generate_video_{p} - {r} - Failed to create video for part {p} question: {q}'.format( p=part, r=request_id, q=question - ) + ), + request_id ) if result is not None: self._logger.info(f'POST - generate_video_{part} - {request_id} - Video created') diff --git a/app/services/impl/third_parties/heygen.py b/app/services/impl/third_parties/heygen.py index 386d326..6b12915 100644 --- a/app/services/impl/third_parties/heygen.py +++ b/app/services/impl/third_parties/heygen.py @@ -14,19 +14,18 @@ class Heygen(IVideoGeneratorService): def __init__(self, client: AsyncClient, token: str): pass - """ self._get_header = { - 'X-Api-Key': heygen_token + 'X-Api-Key': token } self._post_header = { - 'X-Api-Key': heygen_token, + 'X-Api-Key': token, 'Content-Type': 'application/json' } self._http_client = client self._logger = logging.getLogger(__name__) - """ - async def create_video(self, text: str, avatar: str, title="video_title": str): + + async def create_video(self, text: str, avatar: str, title="video_title"): pass # POST TO CREATE VIDEO create_video_url = 'https://api.heygen.com/v2/template/' + avatar + '/generate'