chenxie95 commited on
Commit
7c16cce
·
verified ·
1 Parent(s): 7516058

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -34
app.py CHANGED
@@ -25,20 +25,7 @@ tts_model_collections = {
25
  }
26
 
27
 
28
- def gpu_decorator(func):
29
- return spaces.GPU(func)
30
-
31
-
32
- def load_text_from_file(file):
33
- if file:
34
- with open(file, "r", encoding="utf-8") as f:
35
- text = f.read().strip()
36
- else:
37
- text = ""
38
- return gr.update(value=text)
39
-
40
-
41
- @gpu_decorator
42
  def infer(
43
  ref_audio_orig,
44
  ref_text,
@@ -51,9 +38,9 @@ def infer(
51
  gr.Warning("Please ensure [Reference Audio] [Reference Text] [Text to Generate] are all provided.")
52
  return gr.update(), gr.update(), ref_text
53
 
54
- if seed < 0 or seed > 1024:
55
- gr.Warning("Please set a seed in range 0 ~ 1024.")
56
- seed = np.random.randint(0, 1024)
57
  torch.manual_seed(seed)
58
  used_seed = seed
59
 
@@ -74,22 +61,22 @@ def infer(
74
 
75
  with gr.Blocks() as app_basic_tts:
76
  gr.Markdown("# Batched TTS")
77
- ref_wav_input = gr.Audio(label="Reference Audio", type="filepath")
78
- ref_txt_input = gr.Textbox(label="Reference Text")
79
- gen_txt_input = gr.Textbox(label="Text to Generate")
80
- generate_btn = gr.Button("Synthesize", variant="primary")
81
  with gr.Row():
82
- randomize_seed = gr.Checkbox(
83
- label="Randomize Seed",
84
- info="Check to use a random seed for each generation. Uncheck to use the seed specified.",
85
- value=True,
86
- scale=3,
87
- )
88
- seed_input = gr.Number(show_label=False, value=0, precision=0, scale=1)
89
-
90
- audio_output = gr.Audio(label="Synthesized Audio")
 
 
 
 
 
91
 
92
- @gpu_decorator
93
  def basic_tts(
94
  ref_wav_input,
95
  ref_txt_input,
@@ -98,7 +85,7 @@ with gr.Blocks() as app_basic_tts:
98
  seed_input,
99
  ):
100
  if randomize_seed:
101
- seed_input = np.random.randint(0, 1024)
102
 
103
  audio_out, ref_text_out, used_seed = infer(
104
  ref_wav_input,
@@ -110,7 +97,7 @@ with gr.Blocks() as app_basic_tts:
110
  return audio_out, ref_text_out, used_seed
111
 
112
  ref_wav_input.clear(
113
- lambda: [None, None],
114
  None,
115
  [ref_txt_input],
116
  )
@@ -131,7 +118,9 @@ with gr.Blocks() as app_basic_tts:
131
  with gr.Blocks() as demo:
132
  gr.Markdown(
133
  """
134
- # F5-TTS
 
 
135
  """
136
  )
137
 
 
25
  }
26
 
27
 
28
+ @spaces.GPU
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  def infer(
30
  ref_audio_orig,
31
  ref_text,
 
38
  gr.Warning("Please ensure [Reference Audio] [Reference Text] [Text to Generate] are all provided.")
39
  return gr.update(), gr.update(), ref_text
40
 
41
+ if seed < 0 or seed > 2**31 - 1:
42
+ gr.Warning("Please set a seed in range 0 ~ 2**31 - 1.")
43
+ seed = np.random.randint(0, 2**31 - 1)
44
  torch.manual_seed(seed)
45
  used_seed = seed
46
 
 
61
 
62
  with gr.Blocks() as app_basic_tts:
63
  gr.Markdown("# Batched TTS")
 
 
 
 
64
  with gr.Row():
65
+ with gr.Column():
66
+ ref_wav_input = gr.Audio(label="Reference Audio", type="filepath")
67
+ ref_txt_input = gr.Textbox(label="Reference Text")
68
+ gen_txt_input = gr.Textbox(label="Text to Generate")
69
+ generate_btn = gr.Button("Synthesize", variant="primary")
70
+ with gr.Row():
71
+ randomize_seed = gr.Checkbox(
72
+ label="Randomize Seed",
73
+ info="Check to use a random seed for each generation. Uncheck to use the seed specified.",
74
+ value=True,
75
+ scale=3,
76
+ )
77
+ seed_input = gr.Number(show_label=False, value=0, precision=0, scale=1)
78
+ audio_output = gr.Audio(label="Synthesized Audio")
79
 
 
80
  def basic_tts(
81
  ref_wav_input,
82
  ref_txt_input,
 
85
  seed_input,
86
  ):
87
  if randomize_seed:
88
+ seed_input = np.random.randint(0, 2**31 - 1)
89
 
90
  audio_out, ref_text_out, used_seed = infer(
91
  ref_wav_input,
 
97
  return audio_out, ref_text_out, used_seed
98
 
99
  ref_wav_input.clear(
100
+ lambda: [None],
101
  None,
102
  [ref_txt_input],
103
  )
 
118
  with gr.Blocks() as demo:
119
  gr.Markdown(
120
  """
121
+ # 🗣️ F5-TTS Online Demo for Dev Test
122
+
123
+ Upload/record a reference voice, give reference and generation text, and enjoy playing!
124
  """
125
  )
126