Spaces:
Build error
Build error
File size: 5,581 Bytes
b293d47 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
import os
import platform
import subprocess
import gradio as gr
from shortGPT.api_utils.eleven_api import ElevenLabsAPI
from shortGPT.config.api_db import ApiKeyManager
from shortGPT.config.asset_db import AssetDatabase
class AssetComponentsUtils:
EDGE_TTS = "Free EdgeTTS (lower quality)"
COQUI_TTS = "Free CoquiTTS (needs a powerful GPU)"
ELEVEN_TTS = "ElevenLabs(Very High Quality)"
COQUI_TTS_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",
]
instance_background_video_checkbox = None
instance_background_music_checkbox = None
instance_voiceChoice: dict[gr.Radio] = {}
instance_voiceChoiceTranslation: dict[gr.Radio] = {}
@classmethod
def getBackgroundVideoChoices(cls):
df = AssetDatabase.get_df()
choices = list(df.loc["background video" == df["type"]]["name"])[:20]
return choices
@classmethod
def getBackgroundMusicChoices(cls):
df = AssetDatabase.get_df()
choices = list(df.loc["background music" == df["type"]]["name"])[:20]
return choices
@classmethod
def getElevenlabsVoices(cls):
api_key = ApiKeyManager.get_api_key("ELEVEN LABS")
voices = list(reversed(ElevenLabsAPI(api_key).get_voices().keys()))
return voices
@classmethod
def start_file(cls, path):
if platform.system() == "Windows":
os.startfile(path)
elif platform.system() == "Darwin":
subprocess.Popen(["open", path])
else:
subprocess.Popen(["xdg-open", path])
@classmethod
def background_video_checkbox(cls):
if cls.instance_background_video_checkbox is None:
cls.instance_background_video_checkbox = gr.CheckboxGroup(
choices=cls.getBackgroundVideoChoices(),
interactive=True,
label="Choose background video",
)
return cls.instance_background_video_checkbox
@classmethod
def background_music_checkbox(cls):
if cls.instance_background_music_checkbox is None:
cls.instance_background_music_checkbox = gr.CheckboxGroup(
choices=cls.getBackgroundMusicChoices(),
interactive=True,
label="Choose background music",
)
return cls.instance_background_music_checkbox
@classmethod
def voiceChoice(cls, provider: str = None):
if provider == None:
provider = cls.ELEVEN_TTS
if cls.instance_voiceChoice.get(provider, None) is None:
if provider == cls.ELEVEN_TTS:
print("getting eleven voices")
cls.instance_voiceChoice[provider] = gr.Radio(
cls.getElevenlabsVoices(),
label="Elevenlabs voice",
value="Antoni",
interactive=True,
)
elif provider == cls.COQUI_TTS:
print("getting coqui voices")
cls.instance_voiceChoice[provider] = gr.Dropdown(
cls.COQUI_TTS_VOICES,
label="CoquiTTS voice",
value="Ana Florence",
interactive=True,
)
return cls.instance_voiceChoice[provider]
@classmethod
def voiceChoiceTranslation(cls, provider: str = None):
if provider == None:
provider = cls.ELEVEN_TTS
if cls.instance_voiceChoiceTranslation.get(provider, None) is None:
if provider == cls.ELEVEN_TTS:
cls.instance_voiceChoiceTranslation[provider] = gr.Radio(
cls.getElevenlabsVoices(),
label="Elevenlabs voice",
value="Antoni",
interactive=True,
)
elif provider == cls.COQUI_TTS:
cls.instance_voiceChoiceTranslation[provider] = gr.Radio(
cls.COQUI_TTS_VOICES,
label="CoquiTTS voice",
value="Ana Florence",
interactive=True,
)
return cls.instance_voiceChoiceTranslation[provider]
|