Spaces:
Running
Running
HF Space parameter overrides
Browse files
app.py
CHANGED
|
@@ -38,27 +38,60 @@ AVAILABLE_MODELS = {
|
|
| 38 |
# 'Pheme': 'pheme',
|
| 39 |
# 'MetaVoice': 'metavoice'
|
| 40 |
|
| 41 |
-
# '<Space>':
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
'mrfakename/MetaVoice-1B-v0.1': '/tts#0',
|
| 47 |
|
| 48 |
# xVASynth (CPU)
|
| 49 |
'Pendrokar/xVASynth': '/predict#0',
|
| 50 |
|
| 51 |
# CoquiTTS (CPU)
|
| 52 |
-
'coqui/CoquiTTS': '0#0',
|
|
|
|
| 53 |
# 'pytorch/Tacotron2': '0#0', #old gradio
|
| 54 |
}
|
| 55 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 56 |
SPACE_ID = os.getenv('SPACE_ID')
|
| 57 |
MAX_SAMPLE_TXT_LENGTH = 300
|
| 58 |
MIN_SAMPLE_TXT_LENGTH = 10
|
| 59 |
DB_DATASET_ID = os.getenv('DATASET_ID')
|
| 60 |
DB_NAME = "database.db"
|
| 61 |
|
|
|
|
|
|
|
|
|
|
| 62 |
# If /data available => means local storage is enabled => let's use it!
|
| 63 |
DB_PATH = f"/data/{DB_NAME}" if os.path.isdir("/data") else DB_NAME
|
| 64 |
print(f"Using {DB_PATH}")
|
|
@@ -589,6 +622,8 @@ def synthandreturn(text):
|
|
| 589 |
return_audio_index = int(AVAILABLE_MODELS[model][-1])
|
| 590 |
endpoints = mdl_space.view_api(all_endpoints=True, print_info=False, return_format='dict')
|
| 591 |
|
|
|
|
|
|
|
| 592 |
# has named endpoint
|
| 593 |
if '/' == AVAILABLE_MODELS[model][:1]:
|
| 594 |
# assume the index is one of the first 9 params
|
|
@@ -597,13 +632,6 @@ def synthandreturn(text):
|
|
| 597 |
space_inputs = _get_param_examples(
|
| 598 |
endpoints['named_endpoints'][api_name]['parameters']
|
| 599 |
)
|
| 600 |
-
|
| 601 |
-
# force text to the text input
|
| 602 |
-
space_inputs[0] = text
|
| 603 |
-
|
| 604 |
-
# print(space_inputs)
|
| 605 |
-
results = mdl_space.predict(*space_inputs, api_name=api_name)
|
| 606 |
-
|
| 607 |
# has unnamed endpoint
|
| 608 |
else:
|
| 609 |
# endpoint index is the first character
|
|
@@ -613,15 +641,16 @@ def synthandreturn(text):
|
|
| 613 |
endpoints['unnamed_endpoints'][str(fn_index)]['parameters']
|
| 614 |
)
|
| 615 |
|
| 616 |
-
|
| 617 |
-
space_inputs[0] = text
|
| 618 |
|
| 619 |
-
|
| 620 |
-
|
| 621 |
|
| 622 |
-
|
| 623 |
|
| 624 |
# return path to audio
|
|
|
|
|
|
|
| 625 |
result = results[return_audio_index] if (not isinstance(results, str)) else results
|
| 626 |
else:
|
| 627 |
# Use the private HF Space
|
|
@@ -678,6 +707,16 @@ def synthandreturn(text):
|
|
| 678 |
|
| 679 |
return example_inputs
|
| 680 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 681 |
results = {}
|
| 682 |
thread1 = threading.Thread(target=predict_and_update_result, args=(text, mdl1, results))
|
| 683 |
thread2 = threading.Thread(target=predict_and_update_result, args=(text, mdl2, results))
|
|
@@ -794,4 +833,4 @@ with gr.Blocks(theme=theme, css="footer {visibility: hidden}textbox{resize:none}
|
|
| 794 |
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.")
|
| 795 |
|
| 796 |
|
| 797 |
-
demo.queue(api_open=False, default_concurrency_limit=40).launch(show_api=False)
|
|
|
|
| 38 |
# 'Pheme': 'pheme',
|
| 39 |
# 'MetaVoice': 'metavoice'
|
| 40 |
|
| 41 |
+
# '<Space>': <function>#<return-index-of-audio-param>
|
| 42 |
+
'coqui/xtts': '1#1',
|
| 43 |
+
'collabora/WhisperSpeech': '/whisper_speech_demo#0',
|
| 44 |
+
'myshell-ai/OpenVoice': '1#1',
|
| 45 |
+
'PolyAI/pheme': '/predict#0',
|
| 46 |
'mrfakename/MetaVoice-1B-v0.1': '/tts#0',
|
| 47 |
|
| 48 |
# xVASynth (CPU)
|
| 49 |
'Pendrokar/xVASynth': '/predict#0',
|
| 50 |
|
| 51 |
# CoquiTTS (CPU)
|
| 52 |
+
# 'coqui/CoquiTTS': '0#0',
|
| 53 |
+
|
| 54 |
# 'pytorch/Tacotron2': '0#0', #old gradio
|
| 55 |
}
|
| 56 |
|
| 57 |
+
OVERRIDE_INPUTS = {
|
| 58 |
+
'coqui/xtts': {
|
| 59 |
+
1: 'en',
|
| 60 |
+
2: 'https://cdn-uploads.huggingface.co/production/uploads/641de0213239b631552713e4/iKHHqWxWy6Zfmp6QP6CZZ.wav', # voice sample - Scarlett Johanson
|
| 61 |
+
3: 'https://cdn-uploads.huggingface.co/production/uploads/641de0213239b631552713e4/iKHHqWxWy6Zfmp6QP6CZZ.wav', # voice sample - Scarlett Johanson
|
| 62 |
+
4: False, #use_mic
|
| 63 |
+
5: False, #cleanup_reference
|
| 64 |
+
6: False, #auto_detect
|
| 65 |
+
},
|
| 66 |
+
'collabora/WhisperSpeech': {
|
| 67 |
+
1: 'https://cdn-uploads.huggingface.co/production/uploads/641de0213239b631552713e4/iKHHqWxWy6Zfmp6QP6CZZ.wav', # voice sample - Scarlett Johanson
|
| 68 |
+
2: 'https://cdn-uploads.huggingface.co/production/uploads/641de0213239b631552713e4/iKHHqWxWy6Zfmp6QP6CZZ.wav', # voice sample - Scarlett Johanson
|
| 69 |
+
3: 14.0, #Tempo - Gradio Slider issue: takes min. rather than value
|
| 70 |
+
},
|
| 71 |
+
'myshell-ai/OpenVoice': {
|
| 72 |
+
1: 'default', # style
|
| 73 |
+
2: 'https://cdn-uploads.huggingface.co/production/uploads/641de0213239b631552713e4/iKHHqWxWy6Zfmp6QP6CZZ.wav', # voice sample - Scarlett Johanson
|
| 74 |
+
},
|
| 75 |
+
'PolyAI/pheme': {
|
| 76 |
+
1: 'YOU1000000044_S0000798', # voice
|
| 77 |
+
2: 210,
|
| 78 |
+
3: 0.7, #Tempo - Gradio Slider issue: takes min. rather than value
|
| 79 |
+
},
|
| 80 |
+
'Pendrokar/xVASynth': {
|
| 81 |
+
1: 'ccby_nvidia_hifi_92_F', #fine-tuned voice model name
|
| 82 |
+
3: 1.0, #pacing/duration - Gradio Slider issue: takes min. rather than value
|
| 83 |
+
},
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
SPACE_ID = os.getenv('SPACE_ID')
|
| 87 |
MAX_SAMPLE_TXT_LENGTH = 300
|
| 88 |
MIN_SAMPLE_TXT_LENGTH = 10
|
| 89 |
DB_DATASET_ID = os.getenv('DATASET_ID')
|
| 90 |
DB_NAME = "database.db"
|
| 91 |
|
| 92 |
+
SPACE_ID = 'Pendrokar/TTS-Arena'
|
| 93 |
+
DB_DATASET_ID = 'PenLocal'
|
| 94 |
+
|
| 95 |
# If /data available => means local storage is enabled => let's use it!
|
| 96 |
DB_PATH = f"/data/{DB_NAME}" if os.path.isdir("/data") else DB_NAME
|
| 97 |
print(f"Using {DB_PATH}")
|
|
|
|
| 622 |
return_audio_index = int(AVAILABLE_MODELS[model][-1])
|
| 623 |
endpoints = mdl_space.view_api(all_endpoints=True, print_info=False, return_format='dict')
|
| 624 |
|
| 625 |
+
api_name = None
|
| 626 |
+
fn_index = None
|
| 627 |
# has named endpoint
|
| 628 |
if '/' == AVAILABLE_MODELS[model][:1]:
|
| 629 |
# assume the index is one of the first 9 params
|
|
|
|
| 632 |
space_inputs = _get_param_examples(
|
| 633 |
endpoints['named_endpoints'][api_name]['parameters']
|
| 634 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 635 |
# has unnamed endpoint
|
| 636 |
else:
|
| 637 |
# endpoint index is the first character
|
|
|
|
| 641 |
endpoints['unnamed_endpoints'][str(fn_index)]['parameters']
|
| 642 |
)
|
| 643 |
|
| 644 |
+
space_inputs = _override_params(space_inputs, model)
|
|
|
|
| 645 |
|
| 646 |
+
# force text
|
| 647 |
+
space_inputs[0] = text
|
| 648 |
|
| 649 |
+
results = mdl_space.predict(*space_inputs, api_name=api_name, fn_index=fn_index)
|
| 650 |
|
| 651 |
# return path to audio
|
| 652 |
+
print(results)
|
| 653 |
+
print(return_audio_index)
|
| 654 |
result = results[return_audio_index] if (not isinstance(results, str)) else results
|
| 655 |
else:
|
| 656 |
# Use the private HF Space
|
|
|
|
| 707 |
|
| 708 |
return example_inputs
|
| 709 |
|
| 710 |
+
def _override_params(inputs, modelname):
|
| 711 |
+
try:
|
| 712 |
+
for key,value in OVERRIDE_INPUTS[modelname].items():
|
| 713 |
+
inputs[key] = value
|
| 714 |
+
print(f"Default inputs overridden for {modelname}")
|
| 715 |
+
except:
|
| 716 |
+
pass
|
| 717 |
+
|
| 718 |
+
return inputs
|
| 719 |
+
|
| 720 |
results = {}
|
| 721 |
thread1 = threading.Thread(target=predict_and_update_result, args=(text, mdl1, results))
|
| 722 |
thread2 = threading.Thread(target=predict_and_update_result, args=(text, mdl2, results))
|
|
|
|
| 833 |
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.")
|
| 834 |
|
| 835 |
|
| 836 |
+
demo.queue(api_open=False, default_concurrency_limit=40).launch(show_api=False)
|