mirror of
https://github.com/Paillat-dev/viralfactory.git
synced 2026-01-02 01:06:19 +00:00
🎨 Run linter
This commit is contained in:
@@ -5,5 +5,4 @@ from ..BaseEngine import BaseEngine
|
|||||||
|
|
||||||
class BaseAudioBackgroundEngine(BaseEngine):
|
class BaseAudioBackgroundEngine(BaseEngine):
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_background(self) -> None:
|
def get_background(self) -> None: ...
|
||||||
...
|
|
||||||
|
|||||||
@@ -12,12 +12,16 @@ from . import BaseAudioBackgroundEngine
|
|||||||
|
|
||||||
class MusicAudioBackgroundEngine(BaseAudioBackgroundEngine):
|
class MusicAudioBackgroundEngine(BaseAudioBackgroundEngine):
|
||||||
name = "Music Audio Background Engine"
|
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
|
num_options = 1
|
||||||
|
|
||||||
def __init__(self, options: list[str]):
|
def __init__(self, options: list[str]):
|
||||||
assets = self.get_assets(type="bcg_music")
|
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__()
|
super().__init__()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -54,7 +58,7 @@ class MusicAudioBackgroundEngine(BaseAudioBackgroundEngine):
|
|||||||
audio = audio.with_effects([afx.AudioFadeOut(1)])
|
audio = audio.with_effects([afx.AudioFadeOut(1)])
|
||||||
# change volume to 0.5
|
# change volume to 0.5
|
||||||
audio: mp.AudioFileClip = audio.with_multiply_volume(0.5)
|
audio: mp.AudioFileClip = audio.with_multiply_volume(0.5)
|
||||||
self.ctx.audio.append(audio)
|
return audio
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_settings(cls):
|
def get_settings(cls):
|
||||||
|
|||||||
@@ -5,5 +5,4 @@ from src.engines.BaseEngine import BaseEngine
|
|||||||
|
|
||||||
class BaseBackgroundEngine(BaseEngine):
|
class BaseBackgroundEngine(BaseEngine):
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def get_background(self) -> None:
|
def get_background(self) -> None: ...
|
||||||
...
|
|
||||||
|
|||||||
@@ -17,7 +17,9 @@ class VideoBackgroundEngine(BaseBackgroundEngine):
|
|||||||
|
|
||||||
def __init__(self, options: list[str]):
|
def __init__(self, options: list[str]):
|
||||||
assets = self.get_assets(type="bcg_video")
|
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__()
|
super().__init__()
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -56,7 +58,7 @@ class VideoBackgroundEngine(BaseBackgroundEngine):
|
|||||||
else:
|
else:
|
||||||
clip = clip.with_effects([vfx.Resize(width=self.ctx.width)])
|
clip = clip.with_effects([vfx.Resize(width=self.ctx.width)])
|
||||||
clip = clip.with_position(("center", "center"))
|
clip = clip.with_position(("center", "center"))
|
||||||
self.ctx.index_0.append(clip)
|
return clip
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_settings(cls):
|
def get_settings(cls):
|
||||||
|
|||||||
@@ -5,14 +5,17 @@ import moviepy as mp
|
|||||||
|
|
||||||
from . import BaseCaptioningEngine
|
from . import BaseCaptioningEngine
|
||||||
|
|
||||||
|
|
||||||
def get_available_fonts():
|
def get_available_fonts():
|
||||||
#on windows, the fonts are in the C:\Windows\Fonts and C:\Users\Username\AppData\Local\Microsoft\Windows\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 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 mac, the fonts are in the /Library/Fonts, /System/Library/Fonts, and ~/Library/Fonts directories
|
||||||
if platform.system() == "Windows":
|
if platform.system() == "Windows":
|
||||||
font_dirs = [
|
font_dirs = [
|
||||||
"C:\\Windows\\Fonts",
|
"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":
|
elif platform.system() == "Linux":
|
||||||
font_dirs = ["/usr/share/fonts"]
|
font_dirs = ["/usr/share/fonts"]
|
||||||
@@ -69,14 +72,11 @@ class SimpleCaptioningEngine(BaseCaptioningEngine):
|
|||||||
punctuations = (".", "?", "!", ",", ":", ";")
|
punctuations = (".", "?", "!", ",", ":", ";")
|
||||||
return text.strip().endswith(tuple(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
|
# 3 words per 1000 px, we do the math
|
||||||
max_words = int(self.ctx.width / 1000 * 3)
|
max_words = int(self.ctx.width / 1000 * 3)
|
||||||
|
|
||||||
clips = []
|
clips = []
|
||||||
words = (
|
|
||||||
self.ctx.timed_script.copy()
|
|
||||||
) # List of dicts with "start", "end", and "text"
|
|
||||||
current_line = ""
|
current_line = ""
|
||||||
current_start = words[0]["start"]
|
current_start = words[0]["start"]
|
||||||
current_end = words[0]["end"]
|
current_end = words[0]["end"]
|
||||||
@@ -107,8 +107,7 @@ class SimpleCaptioningEngine(BaseCaptioningEngine):
|
|||||||
current_line.strip(), current_start, words[-1]["end"]
|
current_line.strip(), current_start, words[-1]["end"]
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
return clips
|
||||||
self.ctx.index_7.extend(clips)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_settings(cls):
|
def get_settings(cls):
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ from ..BaseEngine import BaseEngine
|
|||||||
class BaseLLMEngine(BaseEngine):
|
class BaseLLMEngine(BaseEngine):
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
def generate(
|
def generate(
|
||||||
self,
|
self,
|
||||||
system_prompt: str,
|
system_prompt: str,
|
||||||
chat_prompt: str,
|
chat_prompt: str,
|
||||||
max_tokens: int = 512,
|
max_tokens: int = 512,
|
||||||
temperature: float = 1.0,
|
temperature: float = 1.0,
|
||||||
json_mode: bool = False,
|
json_mode: bool = False,
|
||||||
top_p: float = 1,
|
top_p: float = 1,
|
||||||
frequency_penalty: float = 0,
|
frequency_penalty: float = 0,
|
||||||
presence_penalty: float = 0,
|
presence_penalty: float = 0,
|
||||||
) -> str | dict:
|
) -> str | dict:
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -26,4 +26,4 @@ class NoneEngine(BaseEngine):
|
|||||||
Returns:
|
Returns:
|
||||||
list: An empty list as there are no options for NoneEngine.
|
list: An empty list as there are no options for NoneEngine.
|
||||||
"""
|
"""
|
||||||
return []
|
return []
|
||||||
|
|||||||
@@ -103,7 +103,9 @@ class CoquiTTSEngine(BaseTTSEngine):
|
|||||||
try:
|
try:
|
||||||
self.tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2")
|
self.tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2")
|
||||||
except:
|
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"
|
device = "cuda" if torch.cuda.is_available() else "cpu"
|
||||||
self.tts.to(device)
|
self.tts.to(device)
|
||||||
|
|
||||||
@@ -124,9 +126,7 @@ class CoquiTTSEngine(BaseTTSEngine):
|
|||||||
if self.to_force_duration:
|
if self.to_force_duration:
|
||||||
self.force_duration(float(self.duration), path)
|
self.force_duration(float(self.duration), path)
|
||||||
|
|
||||||
self.ctx.duration = self.get_audio_duration(path)
|
return self.get_audio_duration(path)
|
||||||
|
|
||||||
self.ctx.timed_script = self.time_with_whisper(path)
|
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_options(cls) -> list:
|
def get_options(cls) -> list:
|
||||||
@@ -162,10 +162,12 @@ class CoquiTTSEngine(BaseTTSEngine):
|
|||||||
options.append(duration_checkbox)
|
options.append(duration_checkbox)
|
||||||
options.append(duration)
|
options.append(duration)
|
||||||
|
|
||||||
options.append(gr.Checkbox(
|
options.append(
|
||||||
label="I agree to the Coqui public mode license",
|
gr.Checkbox(
|
||||||
info="You must agree to the Coqui TTS terms of service to use this engine: https://coqui.ai/cpml",
|
label="I agree to the Coqui public mode license",
|
||||||
value=False,
|
info="You must agree to the Coqui TTS terms of service to use this engine: https://coqui.ai/cpml",
|
||||||
show_label=True,
|
value=False,
|
||||||
))
|
show_label=True,
|
||||||
|
)
|
||||||
|
)
|
||||||
return options
|
return options
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ class YouTubeUploadEngine(BaseUploadEngine):
|
|||||||
super().__init__(**kwargs)
|
super().__init__(**kwargs)
|
||||||
self.oauth_name = options[0]
|
self.oauth_name = options[0]
|
||||||
self.oauth = self.retrieve_setting(type="oauth_credentials")[self.oauth_name]
|
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]
|
self.hashtags = options[1]
|
||||||
|
|
||||||
@@ -35,11 +37,11 @@ class YouTubeUploadEngine(BaseUploadEngine):
|
|||||||
result = orjson.loads(result)
|
result = orjson.loads(result)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def upload(self):
|
def upload(self, title: str, description: str, path: str):
|
||||||
options = {
|
options = {
|
||||||
"file": self.ctx.get_file_path("final.mp4"),
|
"file": path,
|
||||||
"title": self.ctx.title + " | " + self.hashtags,
|
"title": title + " | " + self.hashtags,
|
||||||
"description": self.ctx.description,
|
"description": description,
|
||||||
"privacyStatus": "private",
|
"privacyStatus": "private",
|
||||||
"category": 28,
|
"category": 28,
|
||||||
}
|
}
|
||||||
@@ -53,7 +55,7 @@ class YouTubeUploadEngine(BaseUploadEngine):
|
|||||||
current_oauths = self.retrieve_setting(type="oauth_credentials") or {}
|
current_oauths = self.retrieve_setting(type="oauth_credentials") or {}
|
||||||
current_oauths[self.oauth_name] = {
|
current_oauths[self.oauth_name] = {
|
||||||
"client_secret": self.oauth["client_secret"],
|
"client_secret": self.oauth["client_secret"],
|
||||||
"credentials": new_oauth
|
"credentials": new_oauth,
|
||||||
}
|
}
|
||||||
self.store_setting(
|
self.store_setting(
|
||||||
type="oauth_credentials",
|
type="oauth_credentials",
|
||||||
@@ -68,7 +70,9 @@ class YouTubeUploadEngine(BaseUploadEngine):
|
|||||||
choices = list(choices.keys())
|
choices = list(choices.keys())
|
||||||
return [
|
return [
|
||||||
gr.Dropdown(
|
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),
|
gr.Textbox(label="Hashtags", value="#shorts", max_lines=1),
|
||||||
]
|
]
|
||||||
@@ -84,7 +88,9 @@ class YouTubeUploadEngine(BaseUploadEngine):
|
|||||||
submit_button = gr.Button("Save")
|
submit_button = gr.Button("Save")
|
||||||
|
|
||||||
def save(binary, clien_secret_name):
|
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)
|
client_secret_json = orjson.loads(binary)
|
||||||
current_client_secrets[clien_secret_name] = client_secret_json
|
current_client_secrets[clien_secret_name] = client_secret_json
|
||||||
cls.store_setting(
|
cls.store_setting(
|
||||||
@@ -93,22 +99,32 @@ class YouTubeUploadEngine(BaseUploadEngine):
|
|||||||
)
|
)
|
||||||
gr.Info(f"{clien_secret_name} saved successfully !")
|
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:
|
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())
|
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)
|
name = gr.Textbox(label="Name", max_lines=1)
|
||||||
login_button = gr.Button("Login", variant="primary")
|
login_button = gr.Button("Login", variant="primary")
|
||||||
|
|
||||||
def login(choosen_client_secret, name):
|
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)
|
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] = {
|
current_oauths[name] = {
|
||||||
"client_secret": choosen_client_secret,
|
"client_secret": choosen_client_secret,
|
||||||
"credentials": new_oauth_entry
|
"credentials": new_oauth_entry,
|
||||||
}
|
}
|
||||||
cls.store_setting(
|
cls.store_setting(
|
||||||
type="oauth_credentials",
|
type="oauth_credentials",
|
||||||
|
|||||||
@@ -11,4 +11,4 @@ class File(Base):
|
|||||||
provider: str = Column(String, nullable=False)
|
provider: str = Column(String, nullable=False)
|
||||||
type: str = Column(String, nullable=True)
|
type: str = Column(String, nullable=True)
|
||||||
path: str = Column(String, nullable=False)
|
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
|
||||||
|
|||||||
@@ -10,4 +10,4 @@ class Setting(Base):
|
|||||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||||
provider: str = Column(String, nullable=False)
|
provider: str = Column(String, nullable=False)
|
||||||
type: str = Column(String, nullable=True)
|
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
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ def resumable_upload(request):
|
|||||||
if retry > MAX_RETRIES:
|
if retry > MAX_RETRIES:
|
||||||
exit("No longer attempting to retry.")
|
exit("No longer attempting to retry.")
|
||||||
|
|
||||||
max_sleep = 2 ** retry
|
max_sleep = 2**retry
|
||||||
sleep_seconds = random.random() * max_sleep
|
sleep_seconds = random.random() * max_sleep
|
||||||
print("Sleeping %f seconds and then retrying..." % sleep_seconds)
|
print("Sleeping %f seconds and then retrying..." % sleep_seconds)
|
||||||
time.sleep(sleep_seconds)
|
time.sleep(sleep_seconds)
|
||||||
|
|||||||
Reference in New Issue
Block a user