Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -18,30 +18,24 @@ def match_target_amplitude(sound, target_dBFS):
|
|
| 18 |
change_in_dBFS = target_dBFS - sound.dBFS
|
| 19 |
return sound.apply_gain(change_in_dBFS)
|
| 20 |
|
| 21 |
-
# from gradio_space_ci import enable_space_ci
|
| 22 |
-
|
| 23 |
-
# enable_space_ci()
|
| 24 |
-
|
| 25 |
|
| 26 |
|
| 27 |
toxicity = Detoxify('original')
|
| 28 |
with open('bsc.txt') as f:
|
| 29 |
sents = f.read().strip().splitlines()
|
|
|
|
|
|
|
| 30 |
####################################
|
| 31 |
# Constants
|
| 32 |
####################################
|
| 33 |
AVAILABLE_MODELS = {
|
| 34 |
'XTTSv2': 'xtts',
|
| 35 |
-
# 'WhisperSpeech': 'whisperspeech',
|
| 36 |
'ElevenLabs': 'eleven',
|
| 37 |
-
# 'OpenVoice': 'openvoice',
|
| 38 |
'OpenVoice V2': 'openvoicev2',
|
| 39 |
'Play.HT 2.0': 'playht',
|
| 40 |
-
# 'MetaVoice': 'metavoice',
|
| 41 |
'MeloTTS': 'melo',
|
| 42 |
'StyleTTS 2': 'styletts2',
|
| 43 |
'GPT-SoVITS': 'sovits',
|
| 44 |
-
# 'Vokan TTS': 'vokan',
|
| 45 |
'VoiceCraft 2.0': 'voicecraft',
|
| 46 |
'Parler TTS': 'parler'
|
| 47 |
}
|
|
@@ -55,14 +49,7 @@ DB_NAME = "database.db"
|
|
| 55 |
# If /data available => means local storage is enabled => let's use it!
|
| 56 |
DB_PATH = f"/data/{DB_NAME}" if os.path.isdir("/data") else DB_NAME
|
| 57 |
print(f"Using {DB_PATH}")
|
| 58 |
-
|
| 59 |
-
CITATION_TEXT = """@misc{tts-arena,
|
| 60 |
-
title = {Text to Speech Arena},
|
| 61 |
-
author = {mrfakename and Srivastav, Vaibhav and Fourrier, Clémentine and Pouget, Lucain and Lacombe, Yoach and main and Gandhi, Sanchit},
|
| 62 |
-
year = 2024,
|
| 63 |
-
publisher = {Hugging Face},
|
| 64 |
-
howpublished = "\\url{https://huggingface.co/spaces/TTS-AGI/TTS-Arena}"
|
| 65 |
-
}"""
|
| 66 |
|
| 67 |
####################################
|
| 68 |
# Functions
|
|
@@ -160,505 +147,7 @@ theme = gr.themes.Base(
|
|
| 160 |
font=[gr.themes.GoogleFont('Libre Franklin'), gr.themes.GoogleFont('Public Sans'), 'system-ui', 'sans-serif'],
|
| 161 |
)
|
| 162 |
|
| 163 |
-
model_names = {
|
| 164 |
-
'styletts2': 'StyleTTS 2',
|
| 165 |
-
'tacotron': 'Tacotron',
|
| 166 |
-
'tacotronph': 'Tacotron Phoneme',
|
| 167 |
-
'tacotrondca': 'Tacotron DCA',
|
| 168 |
-
'speedyspeech': 'Speedy Speech',
|
| 169 |
-
'overflow': 'Overflow TTS',
|
| 170 |
-
'vits': 'VITS',
|
| 171 |
-
'vitsneon': 'VITS Neon',
|
| 172 |
-
'neuralhmm': 'Neural HMM',
|
| 173 |
-
'glow': 'Glow TTS',
|
| 174 |
-
'fastpitch': 'FastPitch',
|
| 175 |
-
'jenny': 'Jenny',
|
| 176 |
-
'tortoise': 'Tortoise TTS',
|
| 177 |
-
'xtts2': 'Coqui XTTSv2',
|
| 178 |
-
'xtts': 'Coqui XTTS',
|
| 179 |
-
'openvoice': 'MyShell OpenVoice',
|
| 180 |
-
'elevenlabs': 'ElevenLabs',
|
| 181 |
-
'openai': 'OpenAI',
|
| 182 |
-
'hierspeech': 'HierSpeech++',
|
| 183 |
-
'pheme': 'PolyAI Pheme',
|
| 184 |
-
'speecht5': 'SpeechT5',
|
| 185 |
-
'metavoice': 'MetaVoice-1B',
|
| 186 |
-
}
|
| 187 |
-
model_licenses = {
|
| 188 |
-
'styletts2': 'MIT',
|
| 189 |
-
'tacotron': 'BSD-3',
|
| 190 |
-
'tacotronph': 'BSD-3',
|
| 191 |
-
'tacotrondca': 'BSD-3',
|
| 192 |
-
'speedyspeech': 'BSD-3',
|
| 193 |
-
'overflow': 'MIT',
|
| 194 |
-
'vits': 'MIT',
|
| 195 |
-
'openvoice': 'MIT',
|
| 196 |
-
'vitsneon': 'BSD-3',
|
| 197 |
-
'neuralhmm': 'MIT',
|
| 198 |
-
'glow': 'MIT',
|
| 199 |
-
'fastpitch': 'Apache 2.0',
|
| 200 |
-
'jenny': 'Jenny License',
|
| 201 |
-
'tortoise': 'Apache 2.0',
|
| 202 |
-
'xtts2': 'CPML (NC)',
|
| 203 |
-
'xtts': 'CPML (NC)',
|
| 204 |
-
'elevenlabs': 'Proprietary',
|
| 205 |
-
'eleven': 'Proprietary',
|
| 206 |
-
'openai': 'Proprietary',
|
| 207 |
-
'hierspeech': 'MIT',
|
| 208 |
-
'pheme': 'CC-BY',
|
| 209 |
-
'speecht5': 'MIT',
|
| 210 |
-
'metavoice': 'Apache 2.0',
|
| 211 |
-
'elevenlabs': 'Proprietary',
|
| 212 |
-
'whisperspeech': 'MIT',
|
| 213 |
-
}
|
| 214 |
-
model_links = {
|
| 215 |
-
'styletts2': 'https://github.com/yl4579/StyleTTS2',
|
| 216 |
-
'tacotron': 'https://github.com/NVIDIA/tacotron2',
|
| 217 |
-
'speedyspeech': 'https://github.com/janvainer/speedyspeech',
|
| 218 |
-
'overflow': 'https://github.com/shivammehta25/OverFlow',
|
| 219 |
-
'vits': 'https://github.com/jaywalnut310/vits',
|
| 220 |
-
'openvoice': 'https://github.com/myshell-ai/OpenVoice',
|
| 221 |
-
'neuralhmm': 'https://github.com/ketranm/neuralHMM',
|
| 222 |
-
'glow': 'https://github.com/jaywalnut310/glow-tts',
|
| 223 |
-
'fastpitch': 'https://fastpitch.github.io/',
|
| 224 |
-
'tortoise': 'https://github.com/neonbjb/tortoise-tts',
|
| 225 |
-
'xtts2': 'https://huggingface.co/coqui/XTTS-v2',
|
| 226 |
-
'xtts': 'https://huggingface.co/coqui/XTTS-v1',
|
| 227 |
-
'elevenlabs': 'https://elevenlabs.io/',
|
| 228 |
-
'openai': 'https://help.openai.com/en/articles/8555505-tts-api',
|
| 229 |
-
'hierspeech': 'https://github.com/sh-lee-prml/HierSpeechpp',
|
| 230 |
-
'pheme': 'https://github.com/PolyAI-LDN/pheme',
|
| 231 |
-
'speecht5': 'https://github.com/microsoft/SpeechT5',
|
| 232 |
-
'metavoice': 'https://github.com/metavoiceio/metavoice-src',
|
| 233 |
-
}
|
| 234 |
-
|
| 235 |
-
def model_license(name):
|
| 236 |
-
print(name)
|
| 237 |
-
for k, v in AVAILABLE_MODELS.items():
|
| 238 |
-
if k == name:
|
| 239 |
-
if v in model_licenses:
|
| 240 |
-
return model_licenses[v]
|
| 241 |
-
print('---')
|
| 242 |
-
return 'Unknown'
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
def get_leaderboard(reveal_prelim = False):
|
| 246 |
-
conn = get_db()
|
| 247 |
-
cursor = conn.cursor()
|
| 248 |
-
sql = 'SELECT name, upvote, downvote FROM model'
|
| 249 |
-
# if not reveal_prelim: sql += ' WHERE EXISTS (SELECT 1 FROM model WHERE (upvote + downvote) > 750)'
|
| 250 |
-
if not reveal_prelim: sql += ' WHERE (upvote + downvote) > 500'
|
| 251 |
-
cursor.execute(sql)
|
| 252 |
-
data = cursor.fetchall()
|
| 253 |
-
df = pd.DataFrame(data, columns=['name', 'upvote', 'downvote'])
|
| 254 |
-
# df['license'] = df['name'].map(model_license)
|
| 255 |
-
df['name'] = df['name'].replace(model_names)
|
| 256 |
-
df['votes'] = df['upvote'] + df['downvote']
|
| 257 |
-
# df['score'] = round((df['upvote'] / df['votes']) * 100, 2) # Percentage score
|
| 258 |
-
|
| 259 |
-
## ELO SCORE
|
| 260 |
-
df['score'] = 1200
|
| 261 |
-
for i in range(len(df)):
|
| 262 |
-
for j in range(len(df)):
|
| 263 |
-
if i != j:
|
| 264 |
-
expected_a = 1 / (1 + 10 ** ((df['score'][j] - df['score'][i]) / 400))
|
| 265 |
-
expected_b = 1 / (1 + 10 ** ((df['score'][i] - df['score'][j]) / 400))
|
| 266 |
-
actual_a = df['upvote'][i] / df['votes'][i]
|
| 267 |
-
actual_b = df['upvote'][j] / df['votes'][j]
|
| 268 |
-
df.at[i, 'score'] += 32 * (actual_a - expected_a)
|
| 269 |
-
df.at[j, 'score'] += 32 * (actual_b - expected_b)
|
| 270 |
-
df['score'] = round(df['score'])
|
| 271 |
-
## ELO SCORE
|
| 272 |
-
df = df.sort_values(by='score', ascending=False)
|
| 273 |
-
df['order'] = ['#' + str(i + 1) for i in range(len(df))]
|
| 274 |
-
# df = df[['name', 'score', 'upvote', 'votes']]
|
| 275 |
-
# df = df[['order', 'name', 'score', 'license', 'votes']]
|
| 276 |
-
df = df[['order', 'name', 'score', 'votes']]
|
| 277 |
-
return df
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
def mkuuid(uid):
|
| 281 |
-
if not uid:
|
| 282 |
-
uid = uuid.uuid4()
|
| 283 |
-
return uid
|
| 284 |
-
|
| 285 |
-
def upvote_model(model, uname):
|
| 286 |
-
conn = get_db()
|
| 287 |
-
cursor = conn.cursor()
|
| 288 |
-
cursor.execute('UPDATE model SET upvote = upvote + 1 WHERE name = ?', (model,))
|
| 289 |
-
if cursor.rowcount == 0:
|
| 290 |
-
cursor.execute('INSERT OR REPLACE INTO model (name, upvote, downvote) VALUES (?, 1, 0)', (model,))
|
| 291 |
-
cursor.execute('INSERT INTO vote (username, model, vote) VALUES (?, ?, ?)', (uname, model, 1,))
|
| 292 |
-
with scheduler.lock:
|
| 293 |
-
conn.commit()
|
| 294 |
-
cursor.close()
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
def log_text(text):
|
| 298 |
-
conn = get_db()
|
| 299 |
-
cursor = conn.cursor()
|
| 300 |
-
cursor.execute('INSERT INTO spokentext (spokentext) VALUES (?)', (text,))
|
| 301 |
-
with scheduler.lock:
|
| 302 |
-
conn.commit()
|
| 303 |
-
cursor.close()
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
def downvote_model(model, uname):
|
| 307 |
-
conn = get_db()
|
| 308 |
-
cursor = conn.cursor()
|
| 309 |
-
cursor.execute('UPDATE model SET downvote = downvote + 1 WHERE name = ?', (model,))
|
| 310 |
-
if cursor.rowcount == 0:
|
| 311 |
-
cursor.execute('INSERT OR REPLACE INTO model (name, upvote, downvote) VALUES (?, 0, 1)', (model,))
|
| 312 |
-
cursor.execute('INSERT INTO vote (username, model, vote) VALUES (?, ?, ?)', (uname, model, -1,))
|
| 313 |
-
with scheduler.lock:
|
| 314 |
-
conn.commit()
|
| 315 |
-
cursor.close()
|
| 316 |
-
|
| 317 |
-
def a_is_better(model1, model2, userid):
|
| 318 |
-
print("A is better", model1, model2)
|
| 319 |
-
if not model1 in AVAILABLE_MODELS.keys() and not model1 in AVAILABLE_MODELS.values():
|
| 320 |
-
raise gr.Error('Sorry, please try voting again.')
|
| 321 |
-
userid = mkuuid(userid)
|
| 322 |
-
if model1 and model2:
|
| 323 |
-
conn = get_db()
|
| 324 |
-
cursor = conn.cursor()
|
| 325 |
-
cursor.execute('INSERT INTO votelog (username, chosen, rejected) VALUES (?, ?, ?)', (str(userid), model1, model2,))
|
| 326 |
-
with scheduler.lock:
|
| 327 |
-
conn.commit()
|
| 328 |
-
cursor.close()
|
| 329 |
-
upvote_model(model1, str(userid))
|
| 330 |
-
downvote_model(model2, str(userid))
|
| 331 |
-
return reload(model1, model2, userid, chose_a=True)
|
| 332 |
-
def b_is_better(model1, model2, userid):
|
| 333 |
-
print("B is better", model1, model2)
|
| 334 |
-
if not model1 in AVAILABLE_MODELS.keys() and not model1 in AVAILABLE_MODELS.values():
|
| 335 |
-
raise gr.Error('Sorry, please try voting again.')
|
| 336 |
-
userid = mkuuid(userid)
|
| 337 |
-
if model1 and model2:
|
| 338 |
-
conn = get_db()
|
| 339 |
-
cursor = conn.cursor()
|
| 340 |
-
cursor.execute('INSERT INTO votelog (username, chosen, rejected) VALUES (?, ?, ?)', (str(userid), model2, model1,))
|
| 341 |
-
with scheduler.lock:
|
| 342 |
-
conn.commit()
|
| 343 |
-
cursor.close()
|
| 344 |
-
upvote_model(model2, str(userid))
|
| 345 |
-
downvote_model(model1, str(userid))
|
| 346 |
-
return reload(model1, model2, userid, chose_b=True)
|
| 347 |
-
def both_bad(model1, model2, userid):
|
| 348 |
-
userid = mkuuid(userid)
|
| 349 |
-
if model1 and model2:
|
| 350 |
-
downvote_model(model1, str(userid))
|
| 351 |
-
downvote_model(model2, str(userid))
|
| 352 |
-
return reload(model1, model2, userid)
|
| 353 |
-
def both_good(model1, model2, userid):
|
| 354 |
-
userid = mkuuid(userid)
|
| 355 |
-
if model1 and model2:
|
| 356 |
-
upvote_model(model1, str(userid))
|
| 357 |
-
upvote_model(model2, str(userid))
|
| 358 |
-
return reload(model1, model2, userid)
|
| 359 |
-
def reload(chosenmodel1=None, chosenmodel2=None, userid=None, chose_a=False, chose_b=False):
|
| 360 |
-
# Select random splits
|
| 361 |
-
# row = random.choice(list(audio_dataset['train']))
|
| 362 |
-
# options = list(random.choice(list(audio_dataset['train'])).keys())
|
| 363 |
-
# split1, split2 = random.sample(options, 2)
|
| 364 |
-
# choice1, choice2 = (row[split1], row[split2])
|
| 365 |
-
# if chosenmodel1 in model_names:
|
| 366 |
-
# chosenmodel1 = model_names[chosenmodel1]
|
| 367 |
-
# if chosenmodel2 in model_names:
|
| 368 |
-
# chosenmodel2 = model_names[chosenmodel2]
|
| 369 |
-
# out = [
|
| 370 |
-
# (choice1['sampling_rate'], choice1['array']),
|
| 371 |
-
# (choice2['sampling_rate'], choice2['array']),
|
| 372 |
-
# split1,
|
| 373 |
-
# split2
|
| 374 |
-
# ]
|
| 375 |
-
# if userid: out.append(userid)
|
| 376 |
-
# if chosenmodel1: out.append(f'This model was {chosenmodel1}')
|
| 377 |
-
# if chosenmodel2: out.append(f'This model was {chosenmodel2}')
|
| 378 |
-
# return out
|
| 379 |
-
# return (f'This model was {chosenmodel1}', f'This model was {chosenmodel2}', gr.update(visible=False), gr.update(visible=False))
|
| 380 |
-
# return (gr.update(variant='secondary', value=chosenmodel1, interactive=False), gr.update(variant='secondary', value=chosenmodel2, interactive=False))
|
| 381 |
-
out = [
|
| 382 |
-
gr.update(interactive=False, visible=False),
|
| 383 |
-
gr.update(interactive=False, visible=False)
|
| 384 |
-
]
|
| 385 |
-
if chose_a == True:
|
| 386 |
-
out.append(gr.update(value=f'Your vote: {chosenmodel1}', interactive=False, visible=True))
|
| 387 |
-
out.append(gr.update(value=f'{chosenmodel2}', interactive=False, visible=True))
|
| 388 |
-
else:
|
| 389 |
-
out.append(gr.update(value=f'{chosenmodel1}', interactive=False, visible=True))
|
| 390 |
-
out.append(gr.update(value=f'Your vote: {chosenmodel2}', interactive=False, visible=True))
|
| 391 |
-
out.append(gr.update(visible=True))
|
| 392 |
-
return out
|
| 393 |
-
|
| 394 |
-
with gr.Blocks() as leaderboard:
|
| 395 |
-
gr.Markdown(LDESC)
|
| 396 |
-
# df = gr.Dataframe(interactive=False, value=get_leaderboard())
|
| 397 |
-
df = gr.Dataframe(interactive=False, min_width=0, wrap=True, column_widths=[30, 200, 50, 50])
|
| 398 |
-
with gr.Row():
|
| 399 |
-
reveal_prelim = gr.Checkbox(label="Reveal preliminary results", info="Show all models, including models with very few human ratings.", scale=1)
|
| 400 |
-
reloadbtn = gr.Button("Refresh", scale=3)
|
| 401 |
-
reveal_prelim.input(get_leaderboard, inputs=[reveal_prelim], outputs=[df])
|
| 402 |
-
leaderboard.load(get_leaderboard, inputs=[reveal_prelim], outputs=[df])
|
| 403 |
-
reloadbtn.click(get_leaderboard, inputs=[reveal_prelim], outputs=[df])
|
| 404 |
-
# gr.Markdown("DISCLAIMER: The licenses listed may not be accurate or up to date, you are responsible for checking the licenses before using the models. Also note that some models may have additional usage restrictions.")
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
def doloudnorm(path):
|
| 408 |
-
data, rate = sf.read(path)
|
| 409 |
-
meter = pyln.Meter(rate)
|
| 410 |
-
loudness = meter.integrated_loudness(data)
|
| 411 |
-
loudness_normalized_audio = pyln.normalize.loudness(data, loudness, -12.0)
|
| 412 |
-
sf.write(path, loudness_normalized_audio, rate)
|
| 413 |
-
|
| 414 |
-
def doresample(path_to_wav):
|
| 415 |
-
pass
|
| 416 |
-
##########################
|
| 417 |
-
# 2x speedup (hopefully) #
|
| 418 |
-
##########################
|
| 419 |
-
|
| 420 |
-
def synthandreturn(text):
|
| 421 |
-
text = text.strip()
|
| 422 |
-
if len(text) > MAX_SAMPLE_TXT_LENGTH:
|
| 423 |
-
raise gr.Error(f'You exceeded the limit of {MAX_SAMPLE_TXT_LENGTH} characters')
|
| 424 |
-
if len(text) < MIN_SAMPLE_TXT_LENGTH:
|
| 425 |
-
raise gr.Error(f'Please input a text longer than {MIN_SAMPLE_TXT_LENGTH} characters')
|
| 426 |
-
if (
|
| 427 |
-
# test toxicity if not prepared text
|
| 428 |
-
text not in sents
|
| 429 |
-
and toxicity.predict(text)['toxicity'] > 0.8
|
| 430 |
-
):
|
| 431 |
-
print(f'Detected toxic content! "{text}"')
|
| 432 |
-
raise gr.Error('Your text failed the toxicity test')
|
| 433 |
-
if not text:
|
| 434 |
-
raise gr.Error(f'You did not enter any text')
|
| 435 |
-
# Check language
|
| 436 |
-
try:
|
| 437 |
-
if not detect(text) == "en":
|
| 438 |
-
gr.Warning('Warning: The input text may not be in English')
|
| 439 |
-
except:
|
| 440 |
-
pass
|
| 441 |
-
# Get two random models
|
| 442 |
-
mdl1, mdl2 = random.sample(list(AVAILABLE_MODELS.keys()), 2)
|
| 443 |
-
log_text(text)
|
| 444 |
-
print("[debug] Using", mdl1, mdl2)
|
| 445 |
-
def predict_and_update_result(text, model, result_storage):
|
| 446 |
-
try:
|
| 447 |
-
if model in AVAILABLE_MODELS:
|
| 448 |
-
result = router.predict(text, AVAILABLE_MODELS[model].lower(), api_name="/synthesize")
|
| 449 |
-
else:
|
| 450 |
-
result = router.predict(text, model.lower(), api_name="/synthesize")
|
| 451 |
-
except:
|
| 452 |
-
raise gr.Error('Unable to call API, please try again :)')
|
| 453 |
-
print('Done with', model)
|
| 454 |
-
# try:
|
| 455 |
-
# doresample(result)
|
| 456 |
-
# except:
|
| 457 |
-
# pass
|
| 458 |
-
try:
|
| 459 |
-
with tempfile.NamedTemporaryFile(suffix='.wav', delete=False) as f:
|
| 460 |
-
audio = AudioSegment.from_file(result)
|
| 461 |
-
current_sr = audio.frame_rate
|
| 462 |
-
if current_sr > 24000:
|
| 463 |
-
audio = audio.set_frame_rate(24000)
|
| 464 |
-
try:
|
| 465 |
-
print('Trying to normalize audio')
|
| 466 |
-
audio = match_target_amplitude(audio, -20)
|
| 467 |
-
except:
|
| 468 |
-
print('[WARN] Unable to normalize audio')
|
| 469 |
-
audio.export(f.name, format="wav")
|
| 470 |
-
os.unlink(result)
|
| 471 |
-
result = f.name
|
| 472 |
-
except:
|
| 473 |
-
pass
|
| 474 |
-
if model in AVAILABLE_MODELS.keys(): model = AVAILABLE_MODELS[model]
|
| 475 |
-
print(model)
|
| 476 |
-
print(f"Running model {model}")
|
| 477 |
-
result_storage[model] = result
|
| 478 |
-
# try:
|
| 479 |
-
# doloudnorm(result)
|
| 480 |
-
# except:
|
| 481 |
-
# pass
|
| 482 |
-
mdl1k = mdl1
|
| 483 |
-
mdl2k = mdl2
|
| 484 |
-
print(mdl1k, mdl2k)
|
| 485 |
-
if mdl1 in AVAILABLE_MODELS.keys(): mdl1k=AVAILABLE_MODELS[mdl1]
|
| 486 |
-
if mdl2 in AVAILABLE_MODELS.keys(): mdl2k=AVAILABLE_MODELS[mdl2]
|
| 487 |
-
results = {}
|
| 488 |
-
print(f"Sending models {mdl1k} and {mdl2k} to API")
|
| 489 |
-
thread1 = threading.Thread(target=predict_and_update_result, args=(text, mdl1k, results))
|
| 490 |
-
thread2 = threading.Thread(target=predict_and_update_result, args=(text, mdl2k, results))
|
| 491 |
-
|
| 492 |
-
thread1.start()
|
| 493 |
-
thread2.start()
|
| 494 |
-
thread1.join()
|
| 495 |
-
thread2.join()
|
| 496 |
-
#debug
|
| 497 |
-
# print(results)
|
| 498 |
-
# print(list(results.keys())[0])
|
| 499 |
-
# y, sr = librosa.load(results[list(results.keys())[0]], sr=None)
|
| 500 |
-
# print(sr)
|
| 501 |
-
# print(list(results.keys())[1])
|
| 502 |
-
# y, sr = librosa.load(results[list(results.keys())[1]], sr=None)
|
| 503 |
-
# print(sr)
|
| 504 |
-
#debug
|
| 505 |
-
# outputs = [text, btn, r2, model1, model2, aud1, aud2, abetter, bbetter, prevmodel1, prevmodel2, nxtroundbtn]
|
| 506 |
-
|
| 507 |
-
print(f"Retrieving models {mdl1k} and {mdl2k} from API")
|
| 508 |
-
return (
|
| 509 |
-
text,
|
| 510 |
-
"Synthesize",
|
| 511 |
-
gr.update(visible=True), # r2
|
| 512 |
-
mdl1, # model1
|
| 513 |
-
mdl2, # model2
|
| 514 |
-
gr.update(visible=True, value=results[mdl1k]), # aud1
|
| 515 |
-
gr.update(visible=True, value=results[mdl2k]), # aud2
|
| 516 |
-
gr.update(visible=True, interactive=False), #abetter
|
| 517 |
-
gr.update(visible=True, interactive=False), #bbetter
|
| 518 |
-
gr.update(visible=False), #prevmodel1
|
| 519 |
-
gr.update(visible=False), #prevmodel2
|
| 520 |
-
gr.update(visible=False), #nxt round btn
|
| 521 |
-
)
|
| 522 |
-
# return (
|
| 523 |
-
# text,
|
| 524 |
-
# "Synthesize",
|
| 525 |
-
# gr.update(visible=True), # r2
|
| 526 |
-
# mdl1, # model1
|
| 527 |
-
# mdl2, # model2
|
| 528 |
-
# # 'Vote to reveal model A', # prevmodel1
|
| 529 |
-
# gr.update(visible=True, value=router.predict(
|
| 530 |
-
# text,
|
| 531 |
-
# AVAILABLE_MODELS[mdl1],
|
| 532 |
-
# api_name="/synthesize"
|
| 533 |
-
# )), # aud1
|
| 534 |
-
# # 'Vote to reveal model B', # prevmodel2
|
| 535 |
-
# gr.update(visible=True, value=router.predict(
|
| 536 |
-
# text,
|
| 537 |
-
# AVAILABLE_MODELS[mdl2],
|
| 538 |
-
# api_name="/synthesize"
|
| 539 |
-
# )), # aud2
|
| 540 |
-
# gr.update(visible=True, interactive=True),
|
| 541 |
-
# gr.update(visible=True, interactive=True),
|
| 542 |
-
# gr.update(visible=False),
|
| 543 |
-
# gr.update(visible=False),
|
| 544 |
-
# gr.update(visible=False), #nxt round btn
|
| 545 |
-
# )
|
| 546 |
-
|
| 547 |
-
def unlock_vote(btn_index, aplayed, bplayed):
|
| 548 |
-
# sample played
|
| 549 |
-
if btn_index == 0:
|
| 550 |
-
aplayed = gr.State(value=True)
|
| 551 |
-
if btn_index == 1:
|
| 552 |
-
bplayed = gr.State(value=True)
|
| 553 |
-
|
| 554 |
-
# both audio samples played
|
| 555 |
-
if bool(aplayed) and bool(bplayed):
|
| 556 |
-
print('Both audio samples played, voting unlocked')
|
| 557 |
-
return [gr.update(interactive=True), gr.update(interactive=True), gr.update(), gr.update()]
|
| 558 |
-
|
| 559 |
-
return [gr.update(), gr.update(), aplayed, bplayed]
|
| 560 |
-
|
| 561 |
-
def randomsent():
|
| 562 |
-
return random.choice(sents), '🎲'
|
| 563 |
-
def clear_stuff():
|
| 564 |
-
return "", "Synthesize", gr.update(visible=False), '', '', gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False), gr.update(visible=False)
|
| 565 |
-
|
| 566 |
-
def disable():
|
| 567 |
-
return [gr.update(interactive=False), gr.update(interactive=False), gr.update(interactive=False)]
|
| 568 |
-
def enable():
|
| 569 |
-
return [gr.update(interactive=True), gr.update(interactive=True), gr.update(interactive=True)]
|
| 570 |
-
with gr.Blocks() as vote:
|
| 571 |
-
# sample played
|
| 572 |
-
#aplayed = gr.State(value=False)
|
| 573 |
-
#bplayed = gr.State(value=False)
|
| 574 |
-
# voter ID
|
| 575 |
-
useridstate = gr.State()
|
| 576 |
-
gr.Markdown(INSTR)
|
| 577 |
-
with gr.Group():
|
| 578 |
-
with gr.Row():
|
| 579 |
-
text = gr.Textbox(container=False, show_label=False, placeholder="Enter text to synthesize", lines=1, max_lines=1, scale=9999999, min_width=0)
|
| 580 |
-
randomt = gr.Button('🎲', scale=0, min_width=0, variant='tool')
|
| 581 |
-
randomt.click(randomsent, outputs=[text, randomt])
|
| 582 |
-
btn = gr.Button("Synthesize", variant='primary')
|
| 583 |
-
model1 = gr.Textbox(interactive=False, lines=1, max_lines=1, visible=False)
|
| 584 |
-
#model1 = gr.Textbox(interactive=False, lines=1, max_lines=1, visible=True)
|
| 585 |
-
model2 = gr.Textbox(interactive=False, lines=1, max_lines=1, visible=False)
|
| 586 |
-
#model2 = gr.Textbox(interactive=False, lines=1, max_lines=1, visible=True)
|
| 587 |
-
with gr.Row(visible=False) as r2:
|
| 588 |
-
with gr.Column():
|
| 589 |
-
with gr.Group():
|
| 590 |
-
aud1 = gr.Audio(interactive=False, show_label=False, show_download_button=False, show_share_button=False, waveform_options={'waveform_progress_color': '#3C82F6'})
|
| 591 |
-
abetter = gr.Button("A is better", variant='primary')
|
| 592 |
-
prevmodel1 = gr.Textbox(interactive=False, show_label=False, container=False, value="Vote to reveal model A", text_align="center", lines=1, max_lines=1, visible=False)
|
| 593 |
-
with gr.Column():
|
| 594 |
-
with gr.Group():
|
| 595 |
-
aud2 = gr.Audio(interactive=False, show_label=False, show_download_button=False, show_share_button=False, waveform_options={'waveform_progress_color': '#3C82F6'})
|
| 596 |
-
bbetter = gr.Button("B is better", variant='primary')
|
| 597 |
-
prevmodel2 = gr.Textbox(interactive=False, show_label=False, container=False, value="Vote to reveal model B", text_align="center", lines=1, max_lines=1, visible=False)
|
| 598 |
-
nxtroundbtn = gr.Button('Next round', visible=False)
|
| 599 |
-
# outputs = [text, btn, r2, model1, model2, prevmodel1, aud1, prevmodel2, aud2, abetter, bbetter]
|
| 600 |
-
outputs = [
|
| 601 |
-
text,
|
| 602 |
-
btn,
|
| 603 |
-
r2,
|
| 604 |
-
model1,
|
| 605 |
-
model2,
|
| 606 |
-
aud1,
|
| 607 |
-
aud2,
|
| 608 |
-
abetter,
|
| 609 |
-
bbetter,
|
| 610 |
-
prevmodel1,
|
| 611 |
-
prevmodel2,
|
| 612 |
-
nxtroundbtn
|
| 613 |
-
]
|
| 614 |
-
"""
|
| 615 |
-
text,
|
| 616 |
-
"Synthesize",
|
| 617 |
-
gr.update(visible=True), # r2
|
| 618 |
-
mdl1, # model1
|
| 619 |
-
mdl2, # model2
|
| 620 |
-
gr.update(visible=True, value=results[mdl1]), # aud1
|
| 621 |
-
gr.update(visible=True, value=results[mdl2]), # aud2
|
| 622 |
-
gr.update(visible=True, interactive=False), #abetter
|
| 623 |
-
gr.update(visible=True, interactive=False), #bbetter
|
| 624 |
-
gr.update(visible=False), #prevmodel1
|
| 625 |
-
gr.update(visible=False), #prevmodel2
|
| 626 |
-
gr.update(visible=False), #nxt round btn"""
|
| 627 |
-
btn.click(disable, outputs=[btn, abetter, bbetter]).then(synthandreturn, inputs=[text], outputs=outputs).then(enable, outputs=[btn, abetter, bbetter])
|
| 628 |
-
nxtroundbtn.click(clear_stuff, outputs=outputs)
|
| 629 |
-
|
| 630 |
-
# Allow interaction with the vote buttons only when both audio samples have finished playing
|
| 631 |
-
#aud1.stop(unlock_vote, outputs=[abetter, bbetter, aplayed, bplayed], inputs=[gr.State(value=0), aplayed, bplayed])
|
| 632 |
-
#aud2.stop(unlock_vote, outputs=[abetter, bbetter, aplayed, bplayed], inputs=[gr.State(value=1), aplayed, bplayed])
|
| 633 |
-
|
| 634 |
-
# nxt_outputs = [prevmodel1, prevmodel2, abetter, bbetter]
|
| 635 |
-
nxt_outputs = [abetter, bbetter, prevmodel1, prevmodel2, nxtroundbtn]
|
| 636 |
-
abetter.click(a_is_better, outputs=nxt_outputs, inputs=[model1, model2, useridstate])
|
| 637 |
-
bbetter.click(b_is_better, outputs=nxt_outputs, inputs=[model1, model2, useridstate])
|
| 638 |
-
# skipbtn.click(b_is_better, outputs=outputs, inputs=[model1, model2, useridstate])
|
| 639 |
-
|
| 640 |
-
# bothbad.click(both_bad, outputs=outputs, inputs=[model1, model2, useridstate])
|
| 641 |
-
# bothgood.click(both_good, outputs=outputs, inputs=[model1, model2, useridstate])
|
| 642 |
-
|
| 643 |
-
# vote.load(reload, outputs=[aud1, aud2, model1, model2])
|
| 644 |
|
| 645 |
-
with gr.Blocks() as about:
|
| 646 |
-
gr.Markdown(ABOUT)
|
| 647 |
-
# with gr.Blocks() as admin:
|
| 648 |
-
# rdb = gr.Button("Reload Audio Dataset")
|
| 649 |
-
# # rdb.click(reload_audio_dataset, outputs=rdb)
|
| 650 |
-
# with gr.Group():
|
| 651 |
-
# dbtext = gr.Textbox(label="Type \"delete db\" to confirm", placeholder="delete db")
|
| 652 |
-
# ddb = gr.Button("Delete DB")
|
| 653 |
-
# ddb.click(del_db, inputs=dbtext, outputs=ddb)
|
| 654 |
-
with gr.Blocks(theme=theme, css="footer {visibility: hidden}textbox{resize:none}", title="TTS Arena") as demo:
|
| 655 |
-
gr.Markdown(DESCR)
|
| 656 |
-
# gr.TabbedInterface([vote, leaderboard, about, admin], ['Vote', 'Leaderboard', 'About', 'Admin (ONLY IN BETA)'])
|
| 657 |
-
gr.TabbedInterface([vote, leaderboard, about], ['🗳️ Vote', '🏆 Leaderboard', '📄 About'])
|
| 658 |
-
if CITATION_TEXT:
|
| 659 |
-
with gr.Row():
|
| 660 |
-
with gr.Accordion("Citation", open=False):
|
| 661 |
-
gr.Markdown(f"If you use this data in your publication, please cite us!\n\nCopy the BibTeX citation to cite this source:\n\n```bibtext\n{CITATION_TEXT}\n```\n\nPlease remember that all generated audio clips should be assumed unsuitable for redistribution or commercial use.")
|
| 662 |
|
| 663 |
|
| 664 |
demo.queue(api_open=False, default_concurrency_limit=40).launch(show_api=False)
|
|
|
|
| 18 |
change_in_dBFS = target_dBFS - sound.dBFS
|
| 19 |
return sound.apply_gain(change_in_dBFS)
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
|
| 23 |
toxicity = Detoxify('original')
|
| 24 |
with open('bsc.txt') as f:
|
| 25 |
sents = f.read().strip().splitlines()
|
| 26 |
+
|
| 27 |
+
|
| 28 |
####################################
|
| 29 |
# Constants
|
| 30 |
####################################
|
| 31 |
AVAILABLE_MODELS = {
|
| 32 |
'XTTSv2': 'xtts',
|
|
|
|
| 33 |
'ElevenLabs': 'eleven',
|
|
|
|
| 34 |
'OpenVoice V2': 'openvoicev2',
|
| 35 |
'Play.HT 2.0': 'playht',
|
|
|
|
| 36 |
'MeloTTS': 'melo',
|
| 37 |
'StyleTTS 2': 'styletts2',
|
| 38 |
'GPT-SoVITS': 'sovits',
|
|
|
|
| 39 |
'VoiceCraft 2.0': 'voicecraft',
|
| 40 |
'Parler TTS': 'parler'
|
| 41 |
}
|
|
|
|
| 49 |
# If /data available => means local storage is enabled => let's use it!
|
| 50 |
DB_PATH = f"/data/{DB_NAME}" if os.path.isdir("/data") else DB_NAME
|
| 51 |
print(f"Using {DB_PATH}")
|
| 52 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
| 54 |
####################################
|
| 55 |
# Functions
|
|
|
|
| 147 |
font=[gr.themes.GoogleFont('Libre Franklin'), gr.themes.GoogleFont('Public Sans'), 'system-ui', 'sans-serif'],
|
| 148 |
)
|
| 149 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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