mirror of
https://github.com/Paillat-dev/viralfactory.git
synced 2026-01-02 01:06:19 +00:00
Formatting & improving imports
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -152,7 +152,7 @@ cython_debug/
|
|||||||
#.idea/
|
#.idea/
|
||||||
|
|
||||||
output/
|
output/
|
||||||
local/*
|
local/
|
||||||
local/presets.json
|
local/presets.json
|
||||||
cookies.txt
|
cookies.txt
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
|
from . import chore
|
||||||
from . import engines
|
from . import engines
|
||||||
from . import utils
|
from . import utils
|
||||||
from . import chore
|
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
import moviepy.editor as mp
|
|
||||||
import time
|
|
||||||
import os
|
import os
|
||||||
import gradio as gr
|
import time
|
||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
import moviepy.editor as mp
|
||||||
|
|
||||||
from .. import engines
|
from .. import engines
|
||||||
from ..utils.prompting import get_prompt
|
|
||||||
from ..models import Video, SessionLocal
|
from ..models import Video, SessionLocal
|
||||||
|
|
||||||
|
|
||||||
@@ -26,18 +24,18 @@ class GenerationContext:
|
|||||||
db.commit()
|
db.commit()
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
powerfulllmengine,
|
powerfulllmengine,
|
||||||
simplellmengine,
|
simplellmengine,
|
||||||
scriptengine,
|
scriptengine,
|
||||||
ttsengine,
|
ttsengine,
|
||||||
captioningengine,
|
captioningengine,
|
||||||
assetsengine,
|
assetsengine,
|
||||||
settingsengine,
|
settingsengine,
|
||||||
backgroundengine,
|
backgroundengine,
|
||||||
metadataengine,
|
metadataengine,
|
||||||
uploadengine,
|
uploadengine,
|
||||||
progress,
|
progress,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.progress = progress
|
self.progress = progress
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from ...utils.prompting import get_prompt
|
|
||||||
from ...chore import GenerationContext
|
from ...chore import GenerationContext
|
||||||
|
from ...utils.prompting import get_prompt
|
||||||
|
|
||||||
|
|
||||||
class AssetsEngineSelector:
|
class AssetsEngineSelector:
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
from abc import ABC, abstractmethod
|
from abc import abstractmethod
|
||||||
|
|
||||||
from ..BaseEngine import BaseEngine
|
from ..BaseEngine import BaseEngine
|
||||||
from typing import TypedDict
|
|
||||||
from moviepy.editor import ImageClip, VideoFileClip
|
|
||||||
|
|
||||||
|
|
||||||
class BaseAssetsEngine(BaseEngine):
|
class BaseAssetsEngine(BaseEngine):
|
||||||
|
|||||||
@@ -1,15 +1,12 @@
|
|||||||
import gradio as gr
|
|
||||||
import openai
|
|
||||||
import moviepy.editor as mp
|
|
||||||
import io
|
|
||||||
import base64
|
|
||||||
import time
|
|
||||||
import requests
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from moviepy.video.fx.resize import resize
|
|
||||||
from typing import Literal, TypedDict
|
from typing import Literal, TypedDict
|
||||||
|
|
||||||
|
import gradio as gr
|
||||||
|
import moviepy.editor as mp
|
||||||
|
import openai
|
||||||
|
import requests
|
||||||
|
from moviepy.video.fx.resize import resize
|
||||||
|
|
||||||
from . import BaseAssetsEngine
|
from . import BaseAssetsEngine
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,12 @@
|
|||||||
|
import os
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
|
from typing import TypedDict
|
||||||
|
|
||||||
import gradio as gr
|
import gradio as gr
|
||||||
import moviepy.editor as mp
|
import moviepy.editor as mp
|
||||||
import io
|
|
||||||
import base64
|
|
||||||
import time
|
|
||||||
import requests
|
|
||||||
import shutil
|
|
||||||
import os
|
|
||||||
|
|
||||||
from google_images_search import GoogleImagesSearch
|
from google_images_search import GoogleImagesSearch
|
||||||
from moviepy.video.fx.resize import resize
|
from moviepy.video.fx.resize import resize
|
||||||
from typing import Literal, TypedDict
|
|
||||||
|
|
||||||
from . import BaseAssetsEngine
|
from . import BaseAssetsEngine
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
|
from .AssetsEngineSelector import AssetsEngineSelector
|
||||||
from .BaseAssetsEngine import BaseAssetsEngine
|
from .BaseAssetsEngine import BaseAssetsEngine
|
||||||
from .DallEAssetsEngine import DallEAssetsEngine
|
from .DallEAssetsEngine import DallEAssetsEngine
|
||||||
from .AssetsEngineSelector import AssetsEngineSelector
|
|
||||||
from .GoogleAssetsEngine import GoogleAssetsEngine
|
from .GoogleAssetsEngine import GoogleAssetsEngine
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
from abc import ABC, abstractmethod
|
from abc import abstractmethod
|
||||||
from ..BaseEngine import BaseEngine
|
|
||||||
|
|
||||||
from moviepy.editor import VideoClip
|
from ..BaseEngine import BaseEngine
|
||||||
|
|
||||||
|
|
||||||
class BaseBackgroundEngine(BaseEngine):
|
class BaseBackgroundEngine(BaseEngine):
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import os
|
import os
|
||||||
import shutil
|
|
||||||
import random
|
import random
|
||||||
|
import shutil
|
||||||
import time
|
import time
|
||||||
|
|
||||||
import gradio as gr
|
import gradio as gr
|
||||||
import moviepy.editor as mp
|
import moviepy.editor as mp
|
||||||
|
|
||||||
from moviepy.video.fx.resize import resize
|
|
||||||
from moviepy.video.fx.crop import crop
|
from moviepy.video.fx.crop import crop
|
||||||
|
|
||||||
from . import BaseBackgroundEngine
|
from . import BaseBackgroundEngine
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
import gradio as gr
|
|
||||||
import moviepy.editor as mp
|
|
||||||
|
|
||||||
from abc import ABC, abstractmethod
|
from abc import ABC, abstractmethod
|
||||||
|
|
||||||
|
import moviepy.editor as mp
|
||||||
from sqlalchemy.future import select
|
from sqlalchemy.future import select
|
||||||
|
|
||||||
from ..chore import GenerationContext
|
from ..chore import GenerationContext
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
from abc import ABC, abstractmethod
|
from abc import abstractmethod
|
||||||
from ..BaseEngine import BaseEngine
|
|
||||||
|
|
||||||
from moviepy.editor import TextClip
|
from ..BaseEngine import BaseEngine
|
||||||
|
|
||||||
|
|
||||||
class BaseCaptioningEngine(BaseEngine):
|
class BaseCaptioningEngine(BaseEngine):
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import gradio as gr
|
import gradio as gr
|
||||||
from moviepy.editor import TextClip
|
from moviepy.editor import TextClip
|
||||||
from PIL import ImageFont
|
|
||||||
from . import BaseCaptioningEngine
|
from . import BaseCaptioningEngine
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -22,15 +22,15 @@ class AnthropicLLMEngine(BaseLLMEngine):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
def generate(
|
def generate(
|
||||||
self,
|
self,
|
||||||
system_prompt: str,
|
system_prompt: str,
|
||||||
chat_prompt: str,
|
chat_prompt: str,
|
||||||
max_tokens: int = 1024,
|
max_tokens: int = 1024,
|
||||||
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:
|
||||||
prompt = f"""{anthropic.HUMAN_PROMPT} {system_prompt} {anthropic.HUMAN_PROMPT} {chat_prompt} {anthropic.AI_PROMPT}"""
|
prompt = f"""{anthropic.HUMAN_PROMPT} {system_prompt} {anthropic.HUMAN_PROMPT} {chat_prompt} {anthropic.AI_PROMPT}"""
|
||||||
if json_mode:
|
if json_mode:
|
||||||
|
|||||||
@@ -1,20 +1,19 @@
|
|||||||
from abc import ABC, abstractmethod
|
from abc import abstractmethod
|
||||||
from ..BaseEngine import BaseEngine
|
|
||||||
|
|
||||||
import openai
|
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,
|
max_tokens: int,
|
||||||
temperature: float,
|
temperature: float,
|
||||||
json_mode: bool,
|
json_mode: bool,
|
||||||
top_p: float,
|
top_p: float,
|
||||||
frequency_penalty: float,
|
frequency_penalty: float,
|
||||||
presence_penalty: float,
|
presence_penalty: float,
|
||||||
) -> str | dict:
|
) -> str | dict:
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
import openai
|
|
||||||
import gradio as gr
|
import gradio as gr
|
||||||
|
import openai
|
||||||
import orjson
|
import orjson
|
||||||
|
|
||||||
from abc import ABC, abstractmethod
|
|
||||||
|
|
||||||
from .BaseLLMEngine import BaseLLMEngine
|
from .BaseLLMEngine import BaseLLMEngine
|
||||||
|
|
||||||
OPENAI_POSSIBLE_MODELS = [ # Theese shall be the openai models supporting force_json
|
OPENAI_POSSIBLE_MODELS = [ # Theese shall be the openai models supporting force_json
|
||||||
@@ -22,15 +20,15 @@ class OpenaiLLMEngine(BaseLLMEngine):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
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:
|
||||||
response = openai.chat.completions.create(
|
response = openai.chat.completions.create(
|
||||||
model=self.model,
|
model=self.model,
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
|
from .AnthropicLLMEngine import AnthropicLLMEngine
|
||||||
from .BaseLLMEngine import BaseLLMEngine
|
from .BaseLLMEngine import BaseLLMEngine
|
||||||
from .OpenaiLLMEngine import OpenaiLLMEngine
|
from .OpenaiLLMEngine import OpenaiLLMEngine
|
||||||
from .AnthropicLLMEngine import AnthropicLLMEngine
|
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from abc import abstractmethod
|
from abc import abstractmethod
|
||||||
from typing import TypedDict
|
|
||||||
|
|
||||||
from .. import BaseEngine
|
from .. import BaseEngine
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
from abc import ABC, abstractmethod
|
from abc import abstractmethod
|
||||||
|
|
||||||
from ..BaseEngine import BaseEngine
|
from ..BaseEngine import BaseEngine
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
from .BaseScriptEngine import BaseScriptEngine
|
|
||||||
import gradio as gr
|
import gradio as gr
|
||||||
|
|
||||||
|
from .BaseScriptEngine import BaseScriptEngine
|
||||||
|
|
||||||
|
|
||||||
class CustomScriptEngine(BaseScriptEngine):
|
class CustomScriptEngine(BaseScriptEngine):
|
||||||
name = "Custom Script Engine"
|
name = "Custom Script Engine"
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import gradio as gr
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import gradio as gr
|
||||||
|
|
||||||
from .BaseScriptEngine import BaseScriptEngine
|
from .BaseScriptEngine import BaseScriptEngine
|
||||||
from ...utils.prompting import get_prompt
|
from ...utils.prompting import get_prompt
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
from .BaseScriptEngine import BaseScriptEngine
|
from .BaseScriptEngine import BaseScriptEngine
|
||||||
from .ShowerThoughtsScriptEngine import ShowerThoughtsScriptEngine
|
|
||||||
from .CustomScriptEngine import CustomScriptEngine
|
from .CustomScriptEngine import CustomScriptEngine
|
||||||
|
from .ShowerThoughtsScriptEngine import ShowerThoughtsScriptEngine
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import gradio as gr
|
import gradio as gr
|
||||||
from abc import ABC, abstractmethod
|
|
||||||
from ..BaseEngine import BaseEngine
|
from ..BaseEngine import BaseEngine
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
|
from abc import abstractmethod
|
||||||
|
from typing import TypedDict
|
||||||
|
|
||||||
import moviepy.editor as mp
|
import moviepy.editor as mp
|
||||||
import whisper_timestamped as wt
|
import whisper_timestamped as wt
|
||||||
|
|
||||||
from typing import TypedDict
|
|
||||||
from torch.cuda import is_available
|
from torch.cuda import is_available
|
||||||
from abc import ABC, abstractmethod
|
|
||||||
|
|
||||||
from ..BaseEngine import BaseEngine
|
from ..BaseEngine import BaseEngine
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
import gradio as gr
|
|
||||||
|
|
||||||
from TTS.api import TTS
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
import gradio as gr
|
||||||
import torch
|
import torch
|
||||||
|
from TTS.api import TTS
|
||||||
|
|
||||||
from .BaseTTSEngine import BaseTTSEngine, Word
|
from .BaseTTSEngine import BaseTTSEngine
|
||||||
|
|
||||||
from ...utils.prompting import get_prompt
|
|
||||||
|
|
||||||
|
|
||||||
class CoquiTTSEngine(BaseTTSEngine):
|
class CoquiTTSEngine(BaseTTSEngine):
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import gradio as gr
|
import gradio as gr
|
||||||
|
|
||||||
from tiktok_uploader.upload import upload_video
|
from tiktok_uploader.upload import upload_video
|
||||||
|
|
||||||
from .BaseUploadEngine import BaseUploadEngine
|
from .BaseUploadEngine import BaseUploadEngine
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import gradio as gr
|
import gradio as gr
|
||||||
import orjson
|
import orjson
|
||||||
|
|
||||||
from google_auth_oauthlib.flow import InstalledAppFlow
|
from google_auth_oauthlib.flow import InstalledAppFlow
|
||||||
|
|
||||||
from . import BaseUploadEngine
|
from . import BaseUploadEngine
|
||||||
from ...utils import youtube_uploading
|
from ...utils import youtube_uploading
|
||||||
|
|
||||||
|
|
||||||
class YouTubeUploadEngine(BaseUploadEngine):
|
class YouTubeUploadEngine(BaseUploadEngine):
|
||||||
name = "YouTube"
|
name = "YouTube"
|
||||||
description = "Upload videos to YouTube"
|
description = "Upload videos to YouTube"
|
||||||
@@ -45,10 +45,10 @@ class YouTubeUploadEngine(BaseUploadEngine):
|
|||||||
try:
|
try:
|
||||||
youtube_uploading.upload(self.oauth["credentials"], options)
|
youtube_uploading.upload(self.oauth["credentials"], options)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
#this means we need to re-authenticate likely
|
# this means we need to re-authenticate likely
|
||||||
# use self.__oauth to re-authenticate
|
# use self.__oauth to re-authenticate
|
||||||
new_oauth = self.__oauth(self.credentials)
|
new_oauth = self.__oauth(self.credentials)
|
||||||
#also update the credentials in the settings
|
# also update the credentials in the settings
|
||||||
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"],
|
||||||
@@ -81,6 +81,7 @@ class YouTubeUploadEngine(BaseUploadEngine):
|
|||||||
label="Client Secret File", file_types=["json"], type="binary"
|
label="Client Secret File", file_types=["json"], type="binary"
|
||||||
)
|
)
|
||||||
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)
|
||||||
@@ -99,6 +100,7 @@ class YouTubeUploadEngine(BaseUploadEngine):
|
|||||||
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)
|
||||||
@@ -112,4 +114,5 @@ class YouTubeUploadEngine(BaseUploadEngine):
|
|||||||
data=current_oauths,
|
data=current_oauths,
|
||||||
)
|
)
|
||||||
gr.Info(f"{name} saved successfully !")
|
gr.Info(f"{name} saved successfully !")
|
||||||
|
|
||||||
login_button.click(login, inputs=[choosen_client_secret, name])
|
login_button.click(login, inputs=[choosen_client_secret, name])
|
||||||
|
|||||||
@@ -1,15 +1,16 @@
|
|||||||
from typing import TypedDict
|
from typing import TypedDict
|
||||||
|
|
||||||
|
from . import AssetsEngine
|
||||||
|
from . import BackgroundEngine
|
||||||
|
from . import CaptioningEngine
|
||||||
|
from . import LLMEngine
|
||||||
|
from . import MetadataEngine
|
||||||
|
from . import ScriptEngine
|
||||||
|
from . import SettingsEngine
|
||||||
|
from . import TTSEngine
|
||||||
|
from . import UploadEngine
|
||||||
from .BaseEngine import BaseEngine
|
from .BaseEngine import BaseEngine
|
||||||
from .NoneEngine import NoneEngine
|
from .NoneEngine import NoneEngine
|
||||||
from . import TTSEngine
|
|
||||||
from . import ScriptEngine
|
|
||||||
from . import LLMEngine
|
|
||||||
from . import CaptioningEngine
|
|
||||||
from . import AssetsEngine
|
|
||||||
from . import SettingsEngine
|
|
||||||
from . import BackgroundEngine
|
|
||||||
from . import MetadataEngine
|
|
||||||
from . import UploadEngine
|
|
||||||
|
|
||||||
|
|
||||||
class EngineDict(TypedDict):
|
class EngineDict(TypedDict):
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"TTSEngine": [
|
"TTSEngine": [
|
||||||
"CoquiTTSEngine",
|
"CoquiTTSEngine",
|
||||||
"ElevenLabsTTSEngine"
|
"ElevenLabsTTSEngine"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,5 @@
|
|||||||
import os
|
|
||||||
|
|
||||||
from sqlalchemy import create_engine
|
from sqlalchemy import create_engine
|
||||||
from sqlalchemy.orm import Session, sessionmaker
|
from sqlalchemy.orm import sessionmaker
|
||||||
|
|
||||||
from . import Base
|
from . import Base
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
from . import Base
|
|
||||||
from typing import Optional
|
|
||||||
from sqlalchemy import String, Column, JSON, Integer
|
from sqlalchemy import String, Column, JSON, Integer
|
||||||
from sqlalchemy.ext.mutable import MutableDict
|
from sqlalchemy.ext.mutable import MutableDict
|
||||||
|
|
||||||
|
from . import Base
|
||||||
|
|
||||||
|
|
||||||
class File(Base):
|
class File(Base):
|
||||||
__tablename__ = "files"
|
__tablename__ = "files"
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
from . import Base
|
|
||||||
from typing import Optional
|
|
||||||
from sqlalchemy import String, Column, JSON, Integer
|
from sqlalchemy import String, Column, JSON, Integer
|
||||||
from sqlalchemy.ext.mutable import MutableDict
|
from sqlalchemy.ext.mutable import MutableDict
|
||||||
|
|
||||||
|
from . import Base
|
||||||
|
|
||||||
|
|
||||||
class Setting(Base):
|
class Setting(Base):
|
||||||
__tablename__ = "Settings"
|
__tablename__ = "Settings"
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
from . import Base
|
from datetime import datetime
|
||||||
from typing import Optional
|
|
||||||
from sqlalchemy import String, Column, JSON, Integer, DateTime
|
from sqlalchemy import String, Column, JSON, Integer, DateTime
|
||||||
from sqlalchemy.ext.mutable import MutableList
|
from sqlalchemy.ext.mutable import MutableList
|
||||||
from datetime import datetime
|
|
||||||
|
from . import Base
|
||||||
|
|
||||||
|
|
||||||
class Video(Base):
|
class Video(Base):
|
||||||
@@ -12,6 +13,6 @@ class Video(Base):
|
|||||||
title: str = Column(String, nullable=False)
|
title: str = Column(String, nullable=False)
|
||||||
description: str = Column(String, nullable=False)
|
description: str = Column(String, nullable=False)
|
||||||
script: str = Column(String, nullable=False)
|
script: str = Column(String, nullable=False)
|
||||||
timed_script: dict = Column(MutableList.as_mutable(JSON), nullable=False)
|
timed_script: dict = Column(MutableList.as_mutable(JSON), nullable=False) # type: ignore
|
||||||
timestamp: datetime = Column(DateTime, nullable=False, default=datetime.now())
|
timestamp: datetime = Column(DateTime, nullable=False, default=datetime.now())
|
||||||
path: str = Column(String, nullable=False)
|
path: str = Column(String, nullable=False)
|
||||||
|
|||||||
@@ -1,7 +1,8 @@
|
|||||||
import yaml
|
|
||||||
import os
|
import os
|
||||||
from typing import TypedDict
|
from typing import TypedDict
|
||||||
|
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
|
||||||
class Prompt(TypedDict):
|
class Prompt(TypedDict):
|
||||||
system: str
|
system: str
|
||||||
@@ -9,7 +10,7 @@ class Prompt(TypedDict):
|
|||||||
|
|
||||||
|
|
||||||
def get_prompt(
|
def get_prompt(
|
||||||
name, *, location: str = "src/chore/prompts", by_file_location: str = None
|
name, *, location: str = "src/chore/prompts", by_file_location: str = None
|
||||||
) -> tuple[str, str]:
|
) -> tuple[str, str]:
|
||||||
if by_file_location:
|
if by_file_location:
|
||||||
path = os.path.join(
|
path = os.path.join(
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
from http import client
|
|
||||||
import httplib2
|
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
|
from http import client
|
||||||
|
|
||||||
import google.oauth2.credentials
|
import google.oauth2.credentials
|
||||||
|
import httplib2
|
||||||
from googleapiclient.discovery import build
|
from googleapiclient.discovery import build
|
||||||
from googleapiclient.errors import HttpError
|
from googleapiclient.errors import HttpError
|
||||||
from googleapiclient.http import MediaFileUpload
|
from googleapiclient.http import MediaFileUpload
|
||||||
@@ -34,6 +34,7 @@ API_VERSION = "v3"
|
|||||||
|
|
||||||
VALID_PRIVACY_STATUSES = ("public", "private", "unlisted")
|
VALID_PRIVACY_STATUSES = ("public", "private", "unlisted")
|
||||||
|
|
||||||
|
|
||||||
def get_youtube(oauth_credentials: dict):
|
def get_youtube(oauth_credentials: dict):
|
||||||
oauth_credentials = google.oauth2.credentials.Credentials(
|
oauth_credentials = google.oauth2.credentials.Credentials(
|
||||||
token=oauth_credentials["token"],
|
token=oauth_credentials["token"],
|
||||||
@@ -45,6 +46,7 @@ def get_youtube(oauth_credentials: dict):
|
|||||||
)
|
)
|
||||||
return build(API_SERVICE_NAME, API_VERSION, credentials=oauth_credentials)
|
return build(API_SERVICE_NAME, API_VERSION, credentials=oauth_credentials)
|
||||||
|
|
||||||
|
|
||||||
def upload(oauth_credentials, options):
|
def upload(oauth_credentials, options):
|
||||||
youtube = get_youtube(oauth_credentials)
|
youtube = get_youtube(oauth_credentials)
|
||||||
tags = None
|
tags = None
|
||||||
@@ -106,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)
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
import os
|
import os
|
||||||
import gradio as gr
|
|
||||||
import orjson
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from src.engines import ENGINES, BaseEngine
|
import gradio as gr
|
||||||
|
import orjson
|
||||||
|
|
||||||
from src.chore import GenerationContext
|
from src.chore import GenerationContext
|
||||||
|
from src.engines import ENGINES, BaseEngine
|
||||||
|
|
||||||
|
|
||||||
class GenerateUI:
|
class GenerateUI:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@@ -12,6 +14,7 @@ class GenerateUI:
|
|||||||
font-size: 5rem !important
|
font-size: 5rem !important
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def get_presets(self):
|
def get_presets(self):
|
||||||
with open("local/presets.json", "r") as f:
|
with open("local/presets.json", "r") as f:
|
||||||
return orjson.loads(f.read())
|
return orjson.loads(f.read())
|
||||||
@@ -53,6 +56,7 @@ class GenerateUI:
|
|||||||
def get_settings_interface(self) -> gr.Blocks:
|
def get_settings_interface(self) -> gr.Blocks:
|
||||||
with gr.Blocks() as interface:
|
with gr.Blocks() as interface:
|
||||||
reload_ui = gr.Button("Reload UI", variant="primary")
|
reload_ui = gr.Button("Reload UI", variant="primary")
|
||||||
|
|
||||||
def reload():
|
def reload():
|
||||||
self.ui.close()
|
self.ui.close()
|
||||||
sys.exit("Reload")
|
sys.exit("Reload")
|
||||||
@@ -115,12 +119,13 @@ class GenerateUI:
|
|||||||
value=None
|
value=None
|
||||||
)
|
)
|
||||||
preset_button = gr.Button("Load")
|
preset_button = gr.Button("Load")
|
||||||
|
|
||||||
def load_preset(preset_name, *inputs) -> list[gr.update]:
|
def load_preset(preset_name, *inputs) -> list[gr.update]:
|
||||||
with open("local/presets.json", "r") as f:
|
with open("local/presets.json", "r") as f:
|
||||||
presets = orjson.loads(f.read())
|
presets = orjson.loads(f.read())
|
||||||
returnable = []
|
returnable = []
|
||||||
if preset_name in presets.keys():
|
if preset_name in presets.keys():
|
||||||
# If the preset exists
|
# If the preset exists
|
||||||
preset = presets[preset_name]
|
preset = presets[preset_name]
|
||||||
for engine_type, engines in ENGINES.items():
|
for engine_type, engines in ENGINES.items():
|
||||||
engines = engines["classes"]
|
engines = engines["classes"]
|
||||||
@@ -128,7 +133,8 @@ class GenerateUI:
|
|||||||
for engine in engines:
|
for engine in engines:
|
||||||
if engine.name in preset.get(engine_type, {}).keys():
|
if engine.name in preset.get(engine_type, {}).keys():
|
||||||
values[0].append(engine.name)
|
values[0].append(engine.name)
|
||||||
values.extend(gr.update(value=value) for value in preset[engine_type][engine.name])
|
values.extend(
|
||||||
|
gr.update(value=value) for value in preset[engine_type][engine.name])
|
||||||
else:
|
else:
|
||||||
values.extend(gr.update() for _ in range(engine.num_options))
|
values.extend(gr.update() for _ in range(engine.num_options))
|
||||||
returnable.extend(values)
|
returnable.extend(values)
|
||||||
@@ -153,7 +159,8 @@ class GenerateUI:
|
|||||||
presets[preset_name] = new_preset
|
presets[preset_name] = new_preset
|
||||||
f.write(orjson.dumps(presets))
|
f.write(orjson.dumps(presets))
|
||||||
return [gr.update(value=presets.keys()), *returnable]
|
return [gr.update(value=presets.keys()), *returnable]
|
||||||
preset_button.click(load_preset, inputs=[preset_dropdown, *inputs], outputs=[preset_dropdown,*inputs])
|
preset_button.click(load_preset, inputs=[preset_dropdown, *inputs],
|
||||||
|
outputs=[preset_dropdown, *inputs])
|
||||||
output_gallery = gr.Markdown("aaa", render=False)
|
output_gallery = gr.Markdown("aaa", render=False)
|
||||||
button.click(
|
button.click(
|
||||||
self.run_generate_interface,
|
self.run_generate_interface,
|
||||||
@@ -197,8 +204,8 @@ class GenerateUI:
|
|||||||
options[engine_type].append(
|
options[engine_type].append(
|
||||||
engine(options=args[: engine.num_options])
|
engine(options=args[: engine.num_options])
|
||||||
)
|
)
|
||||||
args = args[engine.num_options :]
|
args = args[engine.num_options:]
|
||||||
else:
|
else:
|
||||||
# we don't care about this, it's not the selected engine, we throw it away
|
# we don't care about this, it's not the selected engine, we throw it away
|
||||||
args = args[engine.num_options :]
|
args = args[engine.num_options:]
|
||||||
return options
|
return options
|
||||||
@@ -1,4 +1,6 @@
|
|||||||
from . import GenerateUI
|
from . import GenerateUI
|
||||||
|
|
||||||
|
|
||||||
def launch():
|
def launch():
|
||||||
ui_generator = GenerateUI()
|
ui_generator = GenerateUI()
|
||||||
ui_generator.launch_ui()
|
ui_generator.launch_ui()
|
||||||
|
|||||||
Reference in New Issue
Block a user