mirror of
https://github.com/Paillat-dev/viralfactory.git
synced 2026-01-02 01:06:19 +00:00
Some stuff
This commit is contained in:
1
interfaces/__init__.py
Normal file
1
interfaces/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .gradio_ui import GenerateUI
|
||||
51
interfaces/gradio_ui.py
Normal file
51
interfaces/gradio_ui.py
Normal file
@@ -0,0 +1,51 @@
|
||||
import importlib
|
||||
import json
|
||||
import os
|
||||
import gradio as gr
|
||||
from src import engines
|
||||
|
||||
class GenerateUI:
|
||||
def __init__(self):
|
||||
self.engines = self.get_engines()
|
||||
|
||||
def get_engines(self):
|
||||
engines_d = {}
|
||||
with open(os.path.join(os.getcwd(), "src", "engines", "engines.json"), "r") as f:
|
||||
engine_types = json.load(f)
|
||||
for engine_type, engine_list in engine_types.items():
|
||||
engines_d[engine_type] = {}
|
||||
for engine_name in engine_list:
|
||||
module = importlib.import_module(f"src.engines.{engine_type}.{engine_name}")
|
||||
engine_class = getattr(module, engine_name)
|
||||
engines_d[engine_type][engine_name] = engine_class
|
||||
return engines_d
|
||||
|
||||
def launch_ui(self):
|
||||
with gr.Blocks() as main_block:
|
||||
for engine_type, engines in self.engines.items():
|
||||
switch_dropdown = gr.Dropdown(list(engines.keys()), label=engine_type)
|
||||
engine_blocks = []
|
||||
|
||||
for engine_name, engine_class in engines.items():
|
||||
with gr.Blocks(elem_id=f"{engine_type}_{engine_name}_block", visible=False) as engine_block:
|
||||
options = engine_class().get_options()
|
||||
for option in options:
|
||||
engine_block.add(option)
|
||||
engine_blocks.append(engine_block)
|
||||
|
||||
def switch_engine(engine_name, engine_blocks=engine_blocks, switch_dropdown=switch_dropdown):
|
||||
for block in engine_blocks:
|
||||
block.visible = block.elem_id.startswith(f"{engine_type}_{engine_name}")
|
||||
|
||||
switch_dropdown.change(switch_engine, inputs=[switch_dropdown], outputs=engine_blocks)
|
||||
|
||||
# Initially show the first engine's options
|
||||
if engines:
|
||||
first_engine_name = list(engines.keys())[0]
|
||||
switch_engine(first_engine_name)
|
||||
|
||||
main_block.launch()
|
||||
|
||||
if __name__ == "__main__":
|
||||
ui_generator = GenerateUI()
|
||||
ui_generator.launch_ui()
|
||||
5
main.py
Normal file
5
main.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from interfaces import GenerateUI
|
||||
|
||||
if __name__ == "__main__":
|
||||
ui_generator = GenerateUI()
|
||||
ui_generator.launch_ui()
|
||||
1
src/__init__.py
Normal file
1
src/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import engines
|
||||
10
src/engines/BaseEngine.py
Normal file
10
src/engines/BaseEngine.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from abc import ABC, abstractmethod
|
||||
import gradio as gr
|
||||
|
||||
class BaseEngine(ABC):
|
||||
options: list
|
||||
name: str
|
||||
description: str
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
10
src/engines/TTSEngine/BaseTTSEngine.py
Normal file
10
src/engines/TTSEngine/BaseTTSEngine.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from ..BaseEngine import BaseEngine
|
||||
|
||||
|
||||
class BaseTTSEngine(BaseEngine):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def synthesize(self, text: str, path: str) -> str:
|
||||
pass
|
||||
111
src/engines/TTSEngine/CoquiTTSEngine.py
Normal file
111
src/engines/TTSEngine/CoquiTTSEngine.py
Normal file
@@ -0,0 +1,111 @@
|
||||
import gradio as gr
|
||||
import TTS
|
||||
import os
|
||||
import torch
|
||||
|
||||
from .BaseTTSEngine import BaseTTSEngine
|
||||
|
||||
|
||||
class CoquiTTSEngine(BaseTTSEngine):
|
||||
voices = [
|
||||
"Claribel Dervla",
|
||||
"Daisy Studious",
|
||||
"Gracie Wise",
|
||||
"Tammie Ema",
|
||||
"Alison Dietlinde",
|
||||
"Ana Florence",
|
||||
"Annmarie Nele",
|
||||
"Asya Anara",
|
||||
"Brenda Stern",
|
||||
"Gitta Nikolina",
|
||||
"Henriette Usha",
|
||||
"Sofia Hellen",
|
||||
"Tammy Grit",
|
||||
"Tanja Adelina",
|
||||
"Vjollca Johnnie",
|
||||
"Andrew Chipper",
|
||||
"Badr Odhiambo",
|
||||
"Dionisio Schuyler",
|
||||
"Royston Min",
|
||||
"Viktor Eka",
|
||||
"Abrahan Mack",
|
||||
"Adde Michal",
|
||||
"Baldur Sanjin",
|
||||
"Craig Gutsy",
|
||||
"Damien Black",
|
||||
"Gilberto Mathias",
|
||||
"Ilkin Urbano",
|
||||
"Kazuhiko Atallah",
|
||||
"Ludvig Milivoj",
|
||||
"Suad Qasim",
|
||||
"Torcull Diarmuid",
|
||||
"Viktor Menelaos",
|
||||
"Zacharie Aimilios",
|
||||
"Nova Hogarth",
|
||||
"Maja Ruoho",
|
||||
"Uta Obando",
|
||||
"Lidiya Szekeres",
|
||||
"Chandra MacFarland",
|
||||
"Szofi Granger",
|
||||
"Camilla Holmström",
|
||||
"Lilya Stainthorpe",
|
||||
"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 = "Coqui TTS"
|
||||
description = "Coqui TTS engine."
|
||||
languages = [
|
||||
"en", # English
|
||||
"es", # Spanish
|
||||
"fr", # French
|
||||
"de", # German
|
||||
"it", # Italian
|
||||
"pt", # Portuguese
|
||||
"pl", # Polish
|
||||
"tr", # Turkish
|
||||
"ru", # Russian
|
||||
"nl", # Dutch
|
||||
"cs", # Czech
|
||||
"ar", # Arabic
|
||||
"zh-cn", # Chinese (Simplified)
|
||||
"ja", # Japanese
|
||||
"hu", # Hungarian
|
||||
"ko", # Korean
|
||||
"hi", # Hindi
|
||||
]
|
||||
options = [
|
||||
gr.Dropdown(
|
||||
voices, value=voices[0], label="voice", max_choices=1
|
||||
),
|
||||
gr.Dropwdown(
|
||||
languages, value=languages[0], label="language", max_choices=1
|
||||
),
|
||||
]
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
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)
|
||||
|
||||
def synthesize(self, text: str, path: str) -> str:
|
||||
voice = self.options[0].value
|
||||
language = self.options[1].value
|
||||
self.tts.tts_to_file(text=text, file_path=path, lang=language, speaker=voice)
|
||||
return path
|
||||
13
src/engines/TTSEngine/ElevenLabsTTSEngine.py
Normal file
13
src/engines/TTSEngine/ElevenLabsTTSEngine.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from .BaseTTSEngine import AbstractTTSEngine
|
||||
import gradio as gr
|
||||
|
||||
class ElevenLabsTTSEngine(AbstractTTSEngine):
|
||||
options = [gr.Radio(["Neutral", "Happy", "Sad"], label="emotion")]
|
||||
name = "ElevenLabs"
|
||||
description = "ElevenLabs TTS engine."
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
|
||||
def synthesize(self, text: str, path: str) -> str:
|
||||
pass
|
||||
3
src/engines/TTSEngine/__init__.py
Normal file
3
src/engines/TTSEngine/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from .BaseTTSEngine import BaseTTSEngine
|
||||
from .CoquiTTSEngine import CoquiTTSEngine
|
||||
from .ElevenLabsTTSEngine import ElevenLabsTTSEngine
|
||||
2
src/engines/__init__.py
Normal file
2
src/engines/__init__.py
Normal file
@@ -0,0 +1,2 @@
|
||||
from . import TTSEngine
|
||||
from .BaseEngine import BaseEngine
|
||||
6
src/engines/engines.json
Normal file
6
src/engines/engines.json
Normal file
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"TTSEngine": [
|
||||
"CoquiTTSEngine",
|
||||
"ElevenLabsTTSEngine"
|
||||
]
|
||||
}
|
||||
4
src/engines/script/AbstractScriptEngine.py
Normal file
4
src/engines/script/AbstractScriptEngine.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from src.engines.BaseEngine import AbstractEngine
|
||||
|
||||
class AbstractScriptEngine(AbstractEngine):
|
||||
pass
|
||||
6
src/engines/script/ComicalScriptEngine.py
Normal file
6
src/engines/script/ComicalScriptEngine.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from AbstractScriptEngine import AbstractScriptEngine
|
||||
|
||||
class ComicalScriptEngine(AbstractScriptEngine):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.options = {"comicality": ["Low", "Medium", "High"]}
|
||||
6
src/engines/script/DrammaticScriptEngine.py
Normal file
6
src/engines/script/DrammaticScriptEngine.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from AbstractScriptEngine import AbstractScriptEngine
|
||||
|
||||
class DramaticScriptEngine(AbstractScriptEngine):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.options = {"tone": ["Serious", "Light-hearted"]}
|
||||
Reference in New Issue
Block a user