mirror of
https://github.com/Paillat-dev/viralfactory.git
synced 2026-01-02 09:16:19 +00:00
Formatting
This commit is contained in:
@@ -2,6 +2,8 @@ import json
|
|||||||
|
|
||||||
from ...utils.prompting import get_prompt
|
from ...utils.prompting import get_prompt
|
||||||
from ...chore import GenerationContext
|
from ...chore import GenerationContext
|
||||||
|
|
||||||
|
|
||||||
class AssetsEngineSelector:
|
class AssetsEngineSelector:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.ctx: GenerationContext
|
self.ctx: GenerationContext
|
||||||
@@ -11,10 +13,14 @@ class AssetsEngineSelector:
|
|||||||
engines_descriptors = ""
|
engines_descriptors = ""
|
||||||
|
|
||||||
for engine in self.ctx.assetsengine:
|
for engine in self.ctx.assetsengine:
|
||||||
engines_descriptors += f"name: '{engine.name}'\n{json.dumps(engine.specification)}\n"
|
engines_descriptors += (
|
||||||
|
f"name: '{engine.name}'\n{json.dumps(engine.specification)}\n"
|
||||||
|
)
|
||||||
|
|
||||||
system_prompt = system_prompt.replace("{engines}", engines_descriptors)
|
system_prompt = system_prompt.replace("{engines}", engines_descriptors)
|
||||||
chat_prompt = chat_prompt.replace("{caption}", json.dumps(self.ctx.timed_script))
|
chat_prompt = chat_prompt.replace(
|
||||||
|
"{caption}", json.dumps(self.ctx.timed_script)
|
||||||
|
)
|
||||||
|
|
||||||
assets = self.ctx.powerfulllmengine.generate(
|
assets = self.ctx.powerfulllmengine.generate(
|
||||||
system_prompt=system_prompt,
|
system_prompt=system_prompt,
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ from typing import TypedDict
|
|||||||
from moviepy.editor import ImageClip, VideoFileClip
|
from moviepy.editor import ImageClip, VideoFileClip
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class BaseAssetsEngine(BaseEngine):
|
class BaseAssetsEngine(BaseEngine):
|
||||||
"""
|
"""
|
||||||
The base class for all assets engines.
|
The base class for all assets engines.
|
||||||
|
|||||||
@@ -17,8 +17,10 @@ class SimpleCaptioningEngine(BaseCaptioningEngine):
|
|||||||
self.stroke_color = options[4]
|
self.stroke_color = options[4]
|
||||||
|
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def build_caption_object(self, text: str, start: float, end: float) -> TextClip:
|
def build_caption_object(self, text: str, start: float, end: float) -> TextClip:
|
||||||
return TextClip(
|
return (
|
||||||
|
TextClip(
|
||||||
text,
|
text,
|
||||||
fontsize=self.font_size,
|
fontsize=self.font_size,
|
||||||
color=self.font_color,
|
color=self.font_color,
|
||||||
@@ -27,7 +29,12 @@ class SimpleCaptioningEngine(BaseCaptioningEngine):
|
|||||||
stroke_width=self.stroke_width,
|
stroke_width=self.stroke_width,
|
||||||
method="caption",
|
method="caption",
|
||||||
size=(self.ctx.width / 3 * 2, None),
|
size=(self.ctx.width / 3 * 2, None),
|
||||||
).set_position(('center', 0.65), relative=True).set_start(start).set_duration(end - start)
|
)
|
||||||
|
.set_position(("center", 0.65), relative=True)
|
||||||
|
.set_start(start)
|
||||||
|
.set_duration(end - start)
|
||||||
|
)
|
||||||
|
|
||||||
def ends_with_punctuation(self, text: str) -> bool:
|
def ends_with_punctuation(self, text: str) -> bool:
|
||||||
punctuations = (".", "?", "!", ",", ":", ";")
|
punctuations = (".", "?", "!", ",", ":", ";")
|
||||||
return text.strip().endswith(tuple(punctuations))
|
return text.strip().endswith(tuple(punctuations))
|
||||||
@@ -51,7 +58,11 @@ class SimpleCaptioningEngine(BaseCaptioningEngine):
|
|||||||
pause = self.ends_with_punctuation(current_line.strip())
|
pause = self.ends_with_punctuation(current_line.strip())
|
||||||
|
|
||||||
if len(line_with_new_word.split(" ")) > max_words or pause:
|
if len(line_with_new_word.split(" ")) > max_words or pause:
|
||||||
clips.append(self.build_caption_object(current_line.strip(), current_start, current_end))
|
clips.append(
|
||||||
|
self.build_caption_object(
|
||||||
|
current_line.strip(), current_start, current_end
|
||||||
|
)
|
||||||
|
)
|
||||||
current_line = word["text"] # Start a new line with the current word
|
current_line = word["text"] # Start a new line with the current word
|
||||||
current_start = word["start"]
|
current_start = word["start"]
|
||||||
current_end = word["end"]
|
current_end = word["end"]
|
||||||
@@ -62,7 +73,9 @@ class SimpleCaptioningEngine(BaseCaptioningEngine):
|
|||||||
# Don't forget to add the last line if it exists
|
# Don't forget to add the last line if it exists
|
||||||
if current_line:
|
if current_line:
|
||||||
clips.append(
|
clips.append(
|
||||||
self.build_caption_object(current_line.strip(), current_start, words[-1]["end"])
|
self.build_caption_object(
|
||||||
|
current_line.strip(), current_start, words[-1]["end"]
|
||||||
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
return clips
|
return clips
|
||||||
@@ -73,7 +86,7 @@ class SimpleCaptioningEngine(BaseCaptioningEngine):
|
|||||||
with gr.Group():
|
with gr.Group():
|
||||||
font = gr.Dropdown(
|
font = gr.Dropdown(
|
||||||
label="Font",
|
label="Font",
|
||||||
choices=TextClip.list('font'),
|
choices=TextClip.list("font"),
|
||||||
value="Arial",
|
value="Arial",
|
||||||
)
|
)
|
||||||
font_size = gr.Number(
|
font_size = gr.Number(
|
||||||
@@ -93,5 +106,7 @@ class SimpleCaptioningEngine(BaseCaptioningEngine):
|
|||||||
step=1,
|
step=1,
|
||||||
value=6,
|
value=6,
|
||||||
)
|
)
|
||||||
font_stroke_color = gr.ColorPicker(label="Stroke Color", value="#000000")
|
font_stroke_color = gr.ColorPicker(
|
||||||
|
label="Stroke Color", value="#000000"
|
||||||
|
)
|
||||||
return [font, font_size, font_stroke_width, font_color, font_stroke_color]
|
return [font, font_size, font_stroke_width, font_color, font_stroke_color]
|
||||||
|
|||||||
@@ -16,10 +16,13 @@ class SettingsEngine(BaseEngine):
|
|||||||
def load(self):
|
def load(self):
|
||||||
self.ctx.width = self.width
|
self.ctx.width = self.width
|
||||||
self.ctx.height = self.height
|
self.ctx.height = self.height
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_options(cls):
|
def get_options(cls):
|
||||||
# minimum is 720p, maximum is 4k, default is portrait hd
|
# minimum is 720p, maximum is 4k, default is portrait hd
|
||||||
width = gr.Number(value=1080, minimum=720, maximum=3840, label="Width", step=1)
|
width = gr.Number(value=1080, minimum=720, maximum=3840, label="Width", step=1)
|
||||||
height = gr.Number(value=1920, minimum=720, maximum=3840, label="Height", step=1)
|
height = gr.Number(
|
||||||
|
value=1920, minimum=720, maximum=3840, label="Height", step=1
|
||||||
|
)
|
||||||
|
|
||||||
return [width, height]
|
return [width, height]
|
||||||
@@ -8,10 +8,14 @@ class Prompt(TypedDict):
|
|||||||
chat: str
|
chat: str
|
||||||
|
|
||||||
|
|
||||||
def get_prompt(name, *, location: str="src/chore/prompts", by_file_location: str = None) -> tuple[str, str]:
|
def get_prompt(
|
||||||
|
name, *, location: str = "src/chore/prompts", by_file_location: str = None
|
||||||
|
) -> tuple[str, str]:
|
||||||
if by_file_location:
|
if by_file_location:
|
||||||
path = os.path.join(
|
path = os.path.join(
|
||||||
os.path.dirname(os.path.abspath(by_file_location)), "prompts", f"{name}.yaml"
|
os.path.dirname(os.path.abspath(by_file_location)),
|
||||||
|
"prompts",
|
||||||
|
f"{name}.yaml",
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
path = os.path.join(os.getcwd(), location, f"{name}.yaml")
|
path = os.path.join(os.getcwd(), location, f"{name}.yaml")
|
||||||
|
|||||||
Reference in New Issue
Block a user