🎨 Run linter

This commit is contained in:
2024-04-21 21:39:39 +02:00
parent 4cb395d279
commit 0fc86d2661
12 changed files with 77 additions and 56 deletions

View File

@@ -5,5 +5,4 @@ from ..BaseEngine import BaseEngine
class BaseAudioBackgroundEngine(BaseEngine):
@abstractmethod
def get_background(self) -> None:
...
def get_background(self) -> None: ...

View File

@@ -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):

View File

@@ -5,5 +5,4 @@ from src.engines.BaseEngine import BaseEngine
class BaseBackgroundEngine(BaseEngine):
@abstractmethod
def get_background(self) -> None:
...
def get_background(self) -> None: ...

View File

@@ -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):

View File

@@ -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):

View File

@@ -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

View File

@@ -26,4 +26,4 @@ class NoneEngine(BaseEngine):
Returns:
list: An empty list as there are no options for NoneEngine.
"""
return []
return []

View File

@@ -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

View File

@@ -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",

View File

@@ -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

View File

@@ -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

View File

@@ -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)