mrfakename commited on
Commit
d54eecc
·
verified ·
1 Parent(s): 50eaf7e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -19
app.py CHANGED
@@ -1,29 +1,42 @@
1
- import gradio as gr
2
- import os
3
- import spaces
4
 
5
- exec(os.getenv("TTS_CODE"))
 
 
 
 
6
 
7
- ABOUT = """
8
- # Voice Cloning
9
 
10
- Early demo of a TTS model that will be released soon. Training is currently still in progress, these are preliminary checkpoints.
 
 
 
11
 
12
- ## Terms of Use
 
 
 
 
 
 
 
 
 
13
 
14
- * You may only use this app and outputs for non-commercial purposes and may not redistribute the outputs.
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
- inp_audio = gr.Audio(label="Upload a voice sample")
23
- inp_text = gr.Textbox(label="Enter text to speak")
24
- btn_clone = gr.Button("Clone voice")
25
- out_audio = gr.Audio(label="Output")
 
 
 
26
 
27
- btn_clone.click(clone_voice, [inp_audio, inp_text], out_audio)
28
 
29
- demo.queue().launch()
 
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()