From 0fc86d2661b5297b692f750fb577a01b15c375bd Mon Sep 17 00:00:00 2001 From: Paillat Date: Sun, 21 Apr 2024 21:39:39 +0200 Subject: [PATCH] :art: Run linter --- .../BaseAudioBackgroundEngine.py | 3 +- .../MusicAudioBackgroundEngine.py | 10 +++-- .../BackgroundEngine/BaseBackgroundEngine.py | 3 +- .../BackgroundEngine/VideoBackgroundEngine.py | 6 ++- .../SimpleCaptioningEngine.py | 19 ++++---- src/engines/LLMEngine/BaseLLMEngine.py | 18 ++++---- src/engines/NoneEngine.py | 2 +- src/engines/TTSEngine/CoquiTTSEngine.py | 22 +++++----- .../UploadEngine/YouTubeUploadEngine.py | 44 +++++++++++++------ src/models/File.py | 2 +- src/models/Setting.py | 2 +- src/utils/youtube_uploading.py | 2 +- 12 files changed, 77 insertions(+), 56 deletions(-) diff --git a/src/engines/AudioBackgroundEngine/BaseAudioBackgroundEngine.py b/src/engines/AudioBackgroundEngine/BaseAudioBackgroundEngine.py index ef26ef7..c8dc4ed 100644 --- a/src/engines/AudioBackgroundEngine/BaseAudioBackgroundEngine.py +++ b/src/engines/AudioBackgroundEngine/BaseAudioBackgroundEngine.py @@ -5,5 +5,4 @@ from ..BaseEngine import BaseEngine class BaseAudioBackgroundEngine(BaseEngine): @abstractmethod - def get_background(self) -> None: - ... + def get_background(self) -> None: ... diff --git a/src/engines/AudioBackgroundEngine/MusicAudioBackgroundEngine.py b/src/engines/AudioBackgroundEngine/MusicAudioBackgroundEngine.py index 0066ddc..77d2bae 100644 --- a/src/engines/AudioBackgroundEngine/MusicAudioBackgroundEngine.py +++ b/src/engines/AudioBackgroundEngine/MusicAudioBackgroundEngine.py @@ -12,12 +12,16 @@ from . import BaseAudioBackgroundEngine class MusicAudioBackgroundEngine(BaseAudioBackgroundEngine): name = "Music Audio Background Engine" - description = "A basic background engine to set the background audio to a music track." + description = ( + "A basic background engine to set the background audio to a music track." + ) num_options = 1 def __init__(self, options: list[str]): assets = self.get_assets(type="bcg_music") - self.background_audio = [asset for asset in assets if asset.data["name"] == options[0]][0] + self.background_audio = [ + asset for asset in assets if asset.data["name"] == options[0] + ][0] super().__init__() @classmethod @@ -54,7 +58,7 @@ class MusicAudioBackgroundEngine(BaseAudioBackgroundEngine): audio = audio.with_effects([afx.AudioFadeOut(1)]) # change volume to 0.5 audio: mp.AudioFileClip = audio.with_multiply_volume(0.5) - self.ctx.audio.append(audio) + return audio @classmethod def get_settings(cls): diff --git a/src/engines/BackgroundEngine/BaseBackgroundEngine.py b/src/engines/BackgroundEngine/BaseBackgroundEngine.py index 3e51891..a899250 100644 --- a/src/engines/BackgroundEngine/BaseBackgroundEngine.py +++ b/src/engines/BackgroundEngine/BaseBackgroundEngine.py @@ -5,5 +5,4 @@ from src.engines.BaseEngine import BaseEngine class BaseBackgroundEngine(BaseEngine): @abstractmethod - def get_background(self) -> None: - ... + def get_background(self) -> None: ... diff --git a/src/engines/BackgroundEngine/VideoBackgroundEngine.py b/src/engines/BackgroundEngine/VideoBackgroundEngine.py index eb151d0..bf07d60 100644 --- a/src/engines/BackgroundEngine/VideoBackgroundEngine.py +++ b/src/engines/BackgroundEngine/VideoBackgroundEngine.py @@ -17,7 +17,9 @@ class VideoBackgroundEngine(BaseBackgroundEngine): def __init__(self, options: list[str]): assets = self.get_assets(type="bcg_video") - self.background_video = [asset for asset in assets if asset.data["name"] == options[0]][0] + self.background_video = [ + asset for asset in assets if asset.data["name"] == options[0] + ][0] super().__init__() @classmethod @@ -56,7 +58,7 @@ class VideoBackgroundEngine(BaseBackgroundEngine): else: clip = clip.with_effects([vfx.Resize(width=self.ctx.width)]) clip = clip.with_position(("center", "center")) - self.ctx.index_0.append(clip) + return clip @classmethod def get_settings(cls): diff --git a/src/engines/CaptioningEngine/SimpleCaptioningEngine.py b/src/engines/CaptioningEngine/SimpleCaptioningEngine.py index d0cd304..5903098 100644 --- a/src/engines/CaptioningEngine/SimpleCaptioningEngine.py +++ b/src/engines/CaptioningEngine/SimpleCaptioningEngine.py @@ -5,14 +5,17 @@ import moviepy as mp from . import BaseCaptioningEngine + def get_available_fonts(): - #on windows, the fonts are in the C:\Windows\Fonts and C:\Users\Username\AppData\Local\Microsoft\Windows\Fonts - #on linux, the fonts are in the /usr/share/fonts directory - #on mac, the fonts are in the /Library/Fonts, /System/Library/Fonts, and ~/Library/Fonts directories + # on windows, the fonts are in the C:\Windows\Fonts and C:\Users\Username\AppData\Local\Microsoft\Windows\Fonts + # on linux, the fonts are in the /usr/share/fonts directory + # on mac, the fonts are in the /Library/Fonts, /System/Library/Fonts, and ~/Library/Fonts directories if platform.system() == "Windows": font_dirs = [ "C:\\Windows\\Fonts", - "C:\\Users\\{}\\AppData\\Local\\Microsoft\\Windows\\Fonts".format(os.getlogin()), + "C:\\Users\\{}\\AppData\\Local\\Microsoft\\Windows\\Fonts".format( + os.getlogin() + ), ] elif platform.system() == "Linux": font_dirs = ["/usr/share/fonts"] @@ -69,14 +72,11 @@ class SimpleCaptioningEngine(BaseCaptioningEngine): punctuations = (".", "?", "!", ",", ":", ";") return text.strip().endswith(tuple(punctuations)) - def get_captions(self): + def get_captions(self, words: list[dict[str, str]] = None) -> list[mp.TextClip]: # 3 words per 1000 px, we do the math max_words = int(self.ctx.width / 1000 * 3) clips = [] - words = ( - self.ctx.timed_script.copy() - ) # List of dicts with "start", "end", and "text" current_line = "" current_start = words[0]["start"] current_end = words[0]["end"] @@ -107,8 +107,7 @@ class SimpleCaptioningEngine(BaseCaptioningEngine): current_line.strip(), current_start, words[-1]["end"] ) ) - - self.ctx.index_7.extend(clips) + return clips @classmethod def get_settings(cls): diff --git a/src/engines/LLMEngine/BaseLLMEngine.py b/src/engines/LLMEngine/BaseLLMEngine.py index 685f723..2816b89 100644 --- a/src/engines/LLMEngine/BaseLLMEngine.py +++ b/src/engines/LLMEngine/BaseLLMEngine.py @@ -6,14 +6,14 @@ from ..BaseEngine import BaseEngine class BaseLLMEngine(BaseEngine): @abstractmethod def generate( - self, - system_prompt: str, - chat_prompt: str, - max_tokens: int = 512, - temperature: float = 1.0, - json_mode: bool = False, - top_p: float = 1, - frequency_penalty: float = 0, - presence_penalty: float = 0, + self, + system_prompt: str, + chat_prompt: str, + max_tokens: int = 512, + temperature: float = 1.0, + json_mode: bool = False, + top_p: float = 1, + frequency_penalty: float = 0, + presence_penalty: float = 0, ) -> str | dict: pass diff --git a/src/engines/NoneEngine.py b/src/engines/NoneEngine.py index b7fa53e..961d10b 100644 --- a/src/engines/NoneEngine.py +++ b/src/engines/NoneEngine.py @@ -26,4 +26,4 @@ class NoneEngine(BaseEngine): Returns: list: An empty list as there are no options for NoneEngine. """ - return [] \ No newline at end of file + return [] diff --git a/src/engines/TTSEngine/CoquiTTSEngine.py b/src/engines/TTSEngine/CoquiTTSEngine.py index 32e3b5d..5ab18af 100644 --- a/src/engines/TTSEngine/CoquiTTSEngine.py +++ b/src/engines/TTSEngine/CoquiTTSEngine.py @@ -103,7 +103,9 @@ class CoquiTTSEngine(BaseTTSEngine): try: self.tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2") except: - raise Exception("An error occured when loading thr TTS model. Make sure that you have agreed to the TOS in the TTSEngine tab.") + raise Exception( + "An error occured when loading thr TTS model. Make sure that you have agreed to the TOS in the TTSEngine tab." + ) device = "cuda" if torch.cuda.is_available() else "cpu" self.tts.to(device) @@ -124,9 +126,7 @@ class CoquiTTSEngine(BaseTTSEngine): if self.to_force_duration: self.force_duration(float(self.duration), path) - self.ctx.duration = self.get_audio_duration(path) - - self.ctx.timed_script = self.time_with_whisper(path) + return self.get_audio_duration(path) @classmethod def get_options(cls) -> list: @@ -162,10 +162,12 @@ class CoquiTTSEngine(BaseTTSEngine): options.append(duration_checkbox) options.append(duration) - options.append(gr.Checkbox( - label="I agree to the Coqui public mode license", - info="You must agree to the Coqui TTS terms of service to use this engine: https://coqui.ai/cpml", - value=False, - show_label=True, - )) + options.append( + gr.Checkbox( + label="I agree to the Coqui public mode license", + info="You must agree to the Coqui TTS terms of service to use this engine: https://coqui.ai/cpml", + value=False, + show_label=True, + ) + ) return options diff --git a/src/engines/UploadEngine/YouTubeUploadEngine.py b/src/engines/UploadEngine/YouTubeUploadEngine.py index 87a153c..6b24bb6 100644 --- a/src/engines/UploadEngine/YouTubeUploadEngine.py +++ b/src/engines/UploadEngine/YouTubeUploadEngine.py @@ -16,7 +16,9 @@ class YouTubeUploadEngine(BaseUploadEngine): super().__init__(**kwargs) self.oauth_name = options[0] self.oauth = self.retrieve_setting(type="oauth_credentials")[self.oauth_name] - self.credentials = self.retrieve_setting(type="youtube_client_secrets")[self.oauth["client_secret"]] + self.credentials = self.retrieve_setting(type="youtube_client_secrets")[ + self.oauth["client_secret"] + ] self.hashtags = options[1] @@ -35,11 +37,11 @@ class YouTubeUploadEngine(BaseUploadEngine): result = orjson.loads(result) return result - def upload(self): + def upload(self, title: str, description: str, path: str): options = { - "file": self.ctx.get_file_path("final.mp4"), - "title": self.ctx.title + " | " + self.hashtags, - "description": self.ctx.description, + "file": path, + "title": title + " | " + self.hashtags, + "description": description, "privacyStatus": "private", "category": 28, } @@ -53,7 +55,7 @@ class YouTubeUploadEngine(BaseUploadEngine): current_oauths = self.retrieve_setting(type="oauth_credentials") or {} current_oauths[self.oauth_name] = { "client_secret": self.oauth["client_secret"], - "credentials": new_oauth + "credentials": new_oauth, } self.store_setting( type="oauth_credentials", @@ -68,7 +70,9 @@ class YouTubeUploadEngine(BaseUploadEngine): choices = list(choices.keys()) return [ gr.Dropdown( - choices=choices, label="Choose Channel", value=choices[0] if choices else "No channels available !" + choices=choices, + label="Choose Channel", + value=choices[0] if choices else "No channels available !", ), gr.Textbox(label="Hashtags", value="#shorts", max_lines=1), ] @@ -84,7 +88,9 @@ class YouTubeUploadEngine(BaseUploadEngine): submit_button = gr.Button("Save") def save(binary, clien_secret_name): - current_client_secrets = cls.retrieve_setting(type="youtube_client_secrets") or {} + current_client_secrets = ( + cls.retrieve_setting(type="youtube_client_secrets") or {} + ) client_secret_json = orjson.loads(binary) current_client_secrets[clien_secret_name] = client_secret_json cls.store_setting( @@ -93,22 +99,32 @@ class YouTubeUploadEngine(BaseUploadEngine): ) gr.Info(f"{clien_secret_name} saved successfully !") - submit_button.click(save, inputs=[client_secret_file, clien_secret_name]) + submit_button.click( + save, inputs=[client_secret_file, clien_secret_name] + ) with gr.Column() as ytb_oauth: - possible_client_secrets = cls.retrieve_setting(type="youtube_client_secrets") or {} + possible_client_secrets = ( + cls.retrieve_setting(type="youtube_client_secrets") or {} + ) possible_client_secrets = list(possible_client_secrets.keys()) - choosen_client_secret = gr.Dropdown(label="Login secret", choices=possible_client_secrets) + choosen_client_secret = gr.Dropdown( + label="Login secret", choices=possible_client_secrets + ) name = gr.Textbox(label="Name", max_lines=1) login_button = gr.Button("Login", variant="primary") def login(choosen_client_secret, name): - choosen_secret_data = cls.retrieve_setting(type="youtube_client_secrets")[choosen_client_secret] + choosen_secret_data = cls.retrieve_setting( + type="youtube_client_secrets" + )[choosen_client_secret] new_oauth_entry = cls.__oauth(choosen_secret_data) - current_oauths = cls.retrieve_setting(type="oauth_credentials") or {} + current_oauths = ( + cls.retrieve_setting(type="oauth_credentials") or {} + ) current_oauths[name] = { "client_secret": choosen_client_secret, - "credentials": new_oauth_entry + "credentials": new_oauth_entry, } cls.store_setting( type="oauth_credentials", diff --git a/src/models/File.py b/src/models/File.py index de8b884..a9c4e4a 100644 --- a/src/models/File.py +++ b/src/models/File.py @@ -11,4 +11,4 @@ class File(Base): provider: str = Column(String, nullable=False) type: str = Column(String, nullable=True) path: str = Column(String, nullable=False) - data: dict = Column(MutableDict.as_mutable(JSON), nullable=False, default={}) # type: ignore + data: dict = Column(MutableDict.as_mutable(JSON), nullable=False, default={}) # type: ignore diff --git a/src/models/Setting.py b/src/models/Setting.py index 6c7b7b2..24618d4 100644 --- a/src/models/Setting.py +++ b/src/models/Setting.py @@ -10,4 +10,4 @@ class Setting(Base): id = Column(Integer, primary_key=True, autoincrement=True) provider: str = Column(String, nullable=False) type: str = Column(String, nullable=True) - data: dict = Column(MutableDict.as_mutable(JSON), nullable=False, default={}) # type: ignore + data: dict = Column(MutableDict.as_mutable(JSON), nullable=False, default={}) # type: ignore diff --git a/src/utils/youtube_uploading.py b/src/utils/youtube_uploading.py index 348605b..7c1070a 100644 --- a/src/utils/youtube_uploading.py +++ b/src/utils/youtube_uploading.py @@ -108,7 +108,7 @@ def resumable_upload(request): if retry > MAX_RETRIES: exit("No longer attempting to retry.") - max_sleep = 2 ** retry + max_sleep = 2**retry sleep_seconds = random.random() * max_sleep print("Sleeping %f seconds and then retrying..." % sleep_seconds) time.sleep(sleep_seconds)