This commit is contained in:
2024-02-14 17:49:51 +01:00
parent 79d81b96b1
commit 0594458865
22 changed files with 223 additions and 124 deletions

View File

@@ -1,10 +1,16 @@
from abc import ABC, abstractmethod
import gradio as gr
class BaseEngine(ABC):
options: list
num_options: int
name: str
description: str
def __init__(self):
pass
pass
@classmethod
@abstractmethod
def get_options():
...

View File

@@ -0,0 +1,10 @@
from abc import ABC, abstractmethod
from ..BaseEngine import BaseEngine
import openai
class BaseLLMEngine(BaseEngine):
@abstractmethod
def generate(self, system_prompt: str, chat_prompt: str, max_tokens: int, temperature: float, top_p: float, frequency_penalty: float, presence_penalty: float) -> str:
pass

View File

@@ -0,0 +1,29 @@
import openai
import gradio as gr
from abc import ABC, abstractmethod
from .BaseLLMEngine import BaseLLMEngine
OPENAI_POSSIBLE_MODELS = [
"gpt-3.5-turbo-0125",
"gpt-4-turbo-preview",
]
class OpenaiLLMEngine(BaseLLMEngine):
num_options = 1
name = "OpenAI"
description = "OpenAI language model engine."
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) -> str:
... # TODO: Implement this method
def get_options(self) -> list:
return [
gr.Dropdown(
label="Model",
choices=OPENAI_POSSIBLE_MODELS,
max_choices=1,
value=OPENAI_POSSIBLE_MODELS[0]
)
]

View File

@@ -0,0 +1 @@
from .BaseLLMEngine import BaseLLMEngine

View File

@@ -0,0 +1,10 @@
from abc import ABC, abstractmethod
from ..BaseEngine import BaseEngine
class BaseScriptEngine(BaseEngine):
pass
@abstractmethod
def generate(self) -> str:
pass

View File

@@ -0,0 +1,18 @@
from .BaseScriptEngine import BaseScriptEngine
import gradio as gr
class ShowerThoughtsScriptEngine(BaseScriptEngine):
name = "Shower Thoughts"
description = "Generate a Shower Thoughts script"
num_options = 0
def __init__(self, options: list[list | tuple | str | int | float | bool | None]):
super().__init__()
def generate(self, text: str, path: str) -> str:
pass
@classmethod
def get_options(cls) -> list:
return []

View File

@@ -0,0 +1,2 @@
from .BaseScriptEngine import BaseScriptEngine
from .ShowerThoughtsScriptEngine import ShowerThoughtsScriptEngine

View File

@@ -7,4 +7,4 @@ class BaseTTSEngine(BaseEngine):
@abstractmethod
def synthesize(self, text: str, path: str) -> str:
pass
pass

View File

@@ -1,7 +1,9 @@
import gradio as gr
import TTS
# import TTS
import os
import torch
# import torch
from .BaseTTSEngine import BaseTTSEngine
@@ -88,20 +90,7 @@ class CoquiTTSEngine(BaseTTSEngine):
"ko", # Korean
"hi", # Hindi
]
options = [
{
"type": "dropdown",
"label": "Voice",
"choices": voices,
"max": 1,
},
{
"type": "dropdown",
"label": "Language",
"choices": languages,
"max": 1,
},
]
num_options = 2
def __init__(self, options: list):
super().__init__()
@@ -110,10 +99,28 @@ class CoquiTTSEngine(BaseTTSEngine):
self.language = options[1][0]
os.environ["COQUI_TOS_AGREED"] = "1"
self.tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2")
device = "cuda" if torch.cuda.is_available() else "cpu"
self.tts.to(device)
# self.tts = TTS("tts_models/multilingual/multi-dataset/xtts_v2")
# device = "cuda" if torch.cuda.is_available() else "cpu"
# self.tts.to(device)
def synthesize(self, text: str, path: str) -> str:
self.tts.tts_to_file(text=text, file_path=path, lang=self.language, speaker=self.voice)
return path
# self.tts.tts_to_file(text=text, file_path=path, lang=self.language, speaker=self.voice)
return path
@classmethod
def get_options(cls) -> list:
return [
gr.Dropdown(
label="Voice",
choices=cls.voices,
max_choices=1,
value=cls.voices[0],
),
gr.Dropdown(
label="Language",
choices=cls.languages,
max_choices=1,
value=cls.languages[0],
),
]

View File

@@ -1,38 +1,19 @@
from .BaseTTSEngine import BaseTTSEngine
import gradio as gr
class ElevenLabsTTSEngine(BaseTTSEngine):
options = [
{
"type": "dropdown",
"label": "Voice",
"choices": [
"Zofija Kendrick",
"Narelle Moon",
"Barbora MacLean",
"Alexandra Hisakawa",
"Alma María",
"Rosemary Okafor",
"Ige Behringer",
"Filip Traverse",
"Damjan Chapman",
"Wulf Carlevaro",
"Aaron Dreschner",
"Kumar Dahl",
"Eugenio Mataracı",
"Ferran Simen",
"Xavier Hayasaka",
"Luis Moray",
"Marcos Rudaski",
],
}
]
name = "ElevenLabs"
description = "ElevenLabs TTS engine."
num_options = 0
def __init__(self, options: list[list | tuple | str | int | float | bool | None]):
self.voice = options[0][0]
# self.voice = options[0][0]
super().__init__()
def synthesize(self, text: str, path: str) -> str:
pass
pass
@classmethod
def get_options(cls) -> list:
return []

View File

@@ -1,3 +1,3 @@
from .BaseTTSEngine import BaseTTSEngine
from .CoquiTTSEngine import CoquiTTSEngine
from .ElevenLabsTTSEngine import ElevenLabsTTSEngine
from .ElevenLabsTTSEngine import ElevenLabsTTSEngine

View File

@@ -1,2 +1,8 @@
from . import TTSEngine
from .BaseEngine import BaseEngine
from .BaseEngine import BaseEngine
from . import ScriptEngine
ENGINES = {
"TTSEngine": [TTSEngine.CoquiTTSEngine, TTSEngine.ElevenLabsTTSEngine],
"ScriptEngine": [ScriptEngine.ShowerThoughtsScriptEngine],
}

View File

@@ -1,4 +0,0 @@
from src.engines.BaseEngine import AbstractEngine
class AbstractScriptEngine(AbstractEngine):
pass

View File

@@ -1,6 +0,0 @@
from AbstractScriptEngine import AbstractScriptEngine
class ComicalScriptEngine(AbstractScriptEngine):
def __init__(self):
super().__init__()
self.options = {"comicality": ["Low", "Medium", "High"]}

View File

@@ -1,6 +0,0 @@
from AbstractScriptEngine import AbstractScriptEngine
class DramaticScriptEngine(AbstractScriptEngine):
def __init__(self):
super().__init__()
self.options = {"tone": ["Serious", "Light-hearted"]}