Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -1,29 +1,42 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
import spaces
|
4 |
|
5 |
-
|
|
|
|
|
|
|
|
|
6 |
|
7 |
-
|
8 |
-
# Voice Cloning
|
9 |
|
10 |
-
|
|
|
|
|
|
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
|
15 |
-
* You are responsible for obtaining permission to use any audio samples you provide. You may not clone voices that you do not have permission to use.
|
16 |
-
* You agree to use this app responsibly and not to misuse the model.
|
17 |
-
* The authors are not responsible for any misuse of the model. You take full responsibility for your use of the app and outputs.
|
18 |
-
"""
|
19 |
|
20 |
with gr.Blocks() as demo:
|
21 |
gr.Markdown(ABOUT)
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
26 |
|
27 |
-
|
28 |
|
29 |
-
demo.
|
|
|
1 |
+
ABOUT = """
|
2 |
+
# OpenF5 TTS Demo
|
|
|
3 |
|
4 |
+
Model is not released yet, release planned once model has finished training.
|
5 |
+
"""
|
6 |
+
import gradio as gr
|
7 |
+
from f5_tts.api import F5TTS
|
8 |
+
from huggingface_hub import snapshot_download
|
9 |
|
10 |
+
checkpoints_path = snapshot_download("mrfakename/openf5-v2", allow_patterns=["model_*.pt"])
|
|
|
11 |
|
12 |
+
models = {}
|
13 |
+
for checkpoint_path in checkpoints_path:
|
14 |
+
model_name = checkpoint_path.split("/")[-1].replace(".pt", "")
|
15 |
+
models[model_name] = F5TTS(checkpoint_path)
|
16 |
|
17 |
+
def generate_audio(model_name, ref_file, ref_text, gen_text, progress=gr.Progress()):
|
18 |
+
if not ref_file or not gen_text:
|
19 |
+
raise gr.Error("Please provide a reference audio and text to generate")
|
20 |
+
wav, sr, _ = models[model_name].infer(
|
21 |
+
ref_file=ref_file,
|
22 |
+
ref_text=ref_text,
|
23 |
+
gen_text=gen_text,
|
24 |
+
seed=-1, # random seed = -1
|
25 |
+
progress=progress
|
26 |
+
)
|
27 |
|
28 |
+
return (sr, wav)
|
|
|
|
|
|
|
|
|
29 |
|
30 |
with gr.Blocks() as demo:
|
31 |
gr.Markdown(ABOUT)
|
32 |
+
model_name = gr.Dropdown(label="Model", choices=list(models.keys()))
|
33 |
+
ref_file = gr.Audio(label="Reference Audio", type="filepath")
|
34 |
+
gen_text = gr.Textbox(label="Text")
|
35 |
+
btn_generate = gr.Button("Generate Audio", variant="primary")
|
36 |
+
gen_audio = gr.Audio(label="Generated Audio")
|
37 |
+
with gr.Accordion("Advanced Options", open=False):
|
38 |
+
ref_text = gr.Textbox(label="Reference Text")
|
39 |
|
40 |
+
btn_generate.click(generate_audio, [model_name, ref_file, ref_text, gen_text], [gen_audio])
|
41 |
|
42 |
+
demo.launch()
|