mirror of
https://github.com/Paillat-dev/viralfactory.git
synced 2026-01-02 09:16:19 +00:00
Formatting
This commit is contained in:
@@ -33,5 +33,5 @@ class AssetsEngineSelector:
|
||||
assets_opts = [
|
||||
asset["args"] for asset in assets if asset["engine"] == engine.name
|
||||
]
|
||||
clips.extend(engine.get_assets(assets_opts))
|
||||
clips.extend(engine.generate(assets_opts))
|
||||
self.ctx.index_3.extend(clips)
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import TypedDict
|
||||
|
||||
from moviepy.editor import ImageClip, VideoFileClip
|
||||
from abc import abstractmethod
|
||||
|
||||
from ..BaseEngine import BaseEngine
|
||||
|
||||
@@ -21,5 +18,5 @@ class BaseAssetsEngine(BaseEngine):
|
||||
spec_description: str
|
||||
|
||||
@abstractmethod
|
||||
def get_assets(self, options: list) -> list:
|
||||
def generate(self, options: list) -> list:
|
||||
...
|
||||
|
||||
@@ -1,7 +1,4 @@
|
||||
import base64
|
||||
import io
|
||||
import os
|
||||
import time
|
||||
from typing import Literal, TypedDict
|
||||
|
||||
import gradio as gr
|
||||
@@ -41,7 +38,7 @@ class DallEAssetsEngine(BaseAssetsEngine):
|
||||
|
||||
super().__init__()
|
||||
|
||||
def get_assets(self, options: list[Spec]) -> list[mp.ImageClip]:
|
||||
def generate(self, options: list[Spec]) -> list[mp.ImageClip]:
|
||||
max_width = self.ctx.width / 3 * 2
|
||||
clips = []
|
||||
for option in options:
|
||||
@@ -49,7 +46,7 @@ class DallEAssetsEngine(BaseAssetsEngine):
|
||||
start = option["start"]
|
||||
end = option["end"]
|
||||
style = option["style"]
|
||||
size = (
|
||||
size: Literal["1024x1024", "1024x1792", "1792x1024"] = (
|
||||
"1024x1024"
|
||||
if self.aspect_ratio == "square"
|
||||
else "1024x1792"
|
||||
@@ -71,9 +68,9 @@ class DallEAssetsEngine(BaseAssetsEngine):
|
||||
continue
|
||||
else:
|
||||
raise
|
||||
img = requests.get(response.data[0].url)
|
||||
img_bytes = requests.get(response.data[0].url)
|
||||
with open("temp.png", "wb") as f:
|
||||
f.write(img.content)
|
||||
f.write(img_bytes.content)
|
||||
img = mp.ImageClip("temp.png")
|
||||
os.remove("temp.png")
|
||||
|
||||
|
||||
@@ -1,13 +1,9 @@
|
||||
import base64
|
||||
import io
|
||||
import os
|
||||
import shutil
|
||||
import time
|
||||
from typing import Literal, TypedDict
|
||||
from typing import TypedDict
|
||||
|
||||
import gradio as gr
|
||||
import moviepy.editor as mp
|
||||
import requests
|
||||
from google_images_search import GoogleImagesSearch
|
||||
from moviepy.video.fx.resize import resize
|
||||
|
||||
@@ -41,7 +37,7 @@ class GoogleAssetsEngine(BaseAssetsEngine):
|
||||
self.google = GoogleImagesSearch(api_key, project_cx)
|
||||
super().__init__()
|
||||
|
||||
def get_assets(self, options: list[Spec]) -> list[mp.ImageClip]:
|
||||
def generate(self, options: list[Spec]) -> list[mp.ImageClip]:
|
||||
max_width = self.ctx.width / 3 * 2
|
||||
clips = []
|
||||
for option in options:
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from moviepy.editor import VideoClip
|
||||
from abc import abstractmethod
|
||||
|
||||
from ..BaseEngine import BaseEngine
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import time
|
||||
import gradio as gr
|
||||
import moviepy.editor as mp
|
||||
from moviepy.video.fx.crop import crop
|
||||
from moviepy.video.fx.resize import resize
|
||||
|
||||
from . import BaseBackgroundEngine
|
||||
|
||||
@@ -60,7 +59,7 @@ class VideoBackgroundEngine(BaseBackgroundEngine):
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def get_settings(cls) -> list:
|
||||
def get_settings(cls):
|
||||
def add_file(fp: str, name: str, credits: str):
|
||||
if name == "":
|
||||
raise ValueError("Name cannot be empty.")
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
import gradio as gr
|
||||
import moviepy.editor as mp
|
||||
from sqlalchemy.future import select
|
||||
|
||||
@@ -8,6 +7,7 @@ from ..chore import GenerationContext
|
||||
from ..models import SessionLocal, File, Setting
|
||||
|
||||
|
||||
# noinspection PyTypeChecker
|
||||
class BaseEngine(ABC):
|
||||
num_options: int
|
||||
name: str
|
||||
@@ -33,6 +33,7 @@ class BaseEngine(ABC):
|
||||
def get_assets(cls, *, type: str = None, by_id: int = None) -> list[File] | File | None:
|
||||
with SessionLocal() as db:
|
||||
if type:
|
||||
# noinspection PyTypeChecker
|
||||
return (
|
||||
db.execute(
|
||||
select(File).filter(
|
||||
@@ -43,6 +44,7 @@ class BaseEngine(ABC):
|
||||
.all()
|
||||
)
|
||||
elif by_id:
|
||||
# noinspection PyTypeChecker
|
||||
return (
|
||||
db.execute(
|
||||
select(File).filter(
|
||||
@@ -53,6 +55,7 @@ class BaseEngine(ABC):
|
||||
.first()
|
||||
)
|
||||
else:
|
||||
# noinspection PyTypeChecker
|
||||
return (
|
||||
db.execute(select(File).filter(File.provider == cls.name))
|
||||
.scalars()
|
||||
@@ -69,6 +72,7 @@ class BaseEngine(ABC):
|
||||
@classmethod
|
||||
def remove_asset(cls, *, path: str):
|
||||
with SessionLocal() as db:
|
||||
# noinspection PyTypeChecker
|
||||
db.execute(select(File).filter(File.path == path)).delete()
|
||||
db.commit()
|
||||
|
||||
@@ -77,6 +81,7 @@ class BaseEngine(ABC):
|
||||
def store_setting(cls, *, type: str = None, data: dict):
|
||||
with SessionLocal() as db:
|
||||
# check if setting exists
|
||||
# noinspection PyTypeChecker
|
||||
setting = db.execute(
|
||||
select(Setting).filter(
|
||||
Setting.provider == cls.name, Setting.type == type
|
||||
@@ -112,6 +117,7 @@ class BaseEngine(ABC):
|
||||
if not identifier and type:
|
||||
identifier = type
|
||||
if identifier:
|
||||
# noinspection PyTypeChecker
|
||||
result = db.execute(
|
||||
select(Setting).filter(
|
||||
Setting.provider == cls.name, Setting.type == identifier
|
||||
@@ -122,6 +128,7 @@ class BaseEngine(ABC):
|
||||
return result.data
|
||||
return None
|
||||
else:
|
||||
# noinspection PyTypeChecker
|
||||
return [
|
||||
s.data
|
||||
for s in db.execute(
|
||||
@@ -145,12 +152,14 @@ class BaseEngine(ABC):
|
||||
if not identifier and type:
|
||||
identifier = type
|
||||
if identifier:
|
||||
# noinspection PyTypeChecker
|
||||
db.execute(
|
||||
select(Setting).filter(
|
||||
Setting.provider == cls.name, Setting.type == identifier
|
||||
)
|
||||
).delete()
|
||||
else:
|
||||
# noinspection PyTypeChecker
|
||||
db.execute(
|
||||
select(Setting).filter(Setting.provider == cls.name)
|
||||
).delete()
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
from moviepy.editor import TextClip
|
||||
from abc import abstractmethod
|
||||
|
||||
from ..BaseEngine import BaseEngine
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import gradio as gr
|
||||
from PIL import ImageFont
|
||||
from moviepy.editor import TextClip
|
||||
|
||||
from . import BaseCaptioningEngine
|
||||
|
||||
@@ -34,8 +34,9 @@ class AnthropicLLMEngine(BaseLLMEngine):
|
||||
) -> str | dict:
|
||||
prompt = f"""{anthropic.HUMAN_PROMPT} {system_prompt} {anthropic.HUMAN_PROMPT} {chat_prompt} {anthropic.AI_PROMPT}"""
|
||||
if json_mode:
|
||||
# anthopic does not officially support JSON mode, but we can bias the output towards a JSON-like format
|
||||
# anthropic does not officially support JSON mode, but we can bias the output towards a JSON-like format
|
||||
prompt += " {"
|
||||
# noinspection PyArgumentList
|
||||
response: anthropic.types.Completion = self.client.completions.create(
|
||||
max_tokens_to_sample=max_tokens,
|
||||
prompt=prompt,
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
import openai
|
||||
from abc import abstractmethod
|
||||
|
||||
from ..BaseEngine import BaseEngine
|
||||
|
||||
@@ -11,11 +9,11 @@ class BaseLLMEngine(BaseEngine):
|
||||
self,
|
||||
system_prompt: str,
|
||||
chat_prompt: str,
|
||||
max_tokens: int,
|
||||
temperature: float,
|
||||
json_mode: bool,
|
||||
top_p: float,
|
||||
frequency_penalty: float,
|
||||
presence_penalty: float,
|
||||
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
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
import gradio as gr
|
||||
import openai
|
||||
import orjson
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from abc import abstractmethod
|
||||
|
||||
from ..BaseEngine import BaseEngine
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ class CustomScriptEngine(BaseScriptEngine):
|
||||
self.script = options[0]
|
||||
super().__init__()
|
||||
|
||||
def generate(self, *args, **kwargs) -> str:
|
||||
self.ctx.script = self.script.strip().copy()
|
||||
def generate(self, *args, **kwargs):
|
||||
self.ctx.script = self.script.strip()
|
||||
|
||||
@classmethod
|
||||
def get_options(cls) -> list:
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
import gradio as gr
|
||||
|
||||
from ..BaseEngine import BaseEngine
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from abc import abstractmethod
|
||||
from typing import TypedDict
|
||||
|
||||
import moviepy.editor as mp
|
||||
|
||||
@@ -4,8 +4,7 @@ import gradio as gr
|
||||
import torch
|
||||
from TTS.api import TTS
|
||||
|
||||
from .BaseTTSEngine import BaseTTSEngine, Word
|
||||
from ...utils.prompting import get_prompt
|
||||
from .BaseTTSEngine import BaseTTSEngine
|
||||
|
||||
|
||||
class CoquiTTSEngine(BaseTTSEngine):
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
from typing import TypedDict
|
||||
|
||||
from . import AssetsEngine
|
||||
from . import BackgroundEngine
|
||||
from . import CaptioningEngine
|
||||
|
||||
Reference in New Issue
Block a user