multimodalart HF Staff commited on
Commit
ed4c899
·
verified ·
1 Parent(s): 0d8b898

Gradio 6 theme/css on launch, tighter GPU duration, cleaner edit transcript

Browse files
Files changed (1) hide show
  1. app.py +18 -7
app.py CHANGED
@@ -8,6 +8,7 @@ Three capabilities of https://huggingface.co/FireRedTeam/FireRedTTS3 :
8
 
9
  import functools
10
  import os
 
11
  import urllib.request
12
 
13
  import spaces # noqa: F401 (must precede torch / CUDA imports)
@@ -134,6 +135,16 @@ def _to_gradio_audio(audio: torch.Tensor, sr: int):
134
  return sr, (x * 32767.0).astype(np.int16)
135
 
136
 
 
 
 
 
 
 
 
 
 
 
137
  def _check_text(text: str, what: str = "Text"):
138
  text = (text or "").strip()
139
  if not text:
@@ -147,7 +158,7 @@ def _check_text(text: str, what: str = "Text"):
147
  # --------------------------------------------------------------------------- #
148
  # Inference
149
  # --------------------------------------------------------------------------- #
150
- @spaces.GPU(duration=150)
151
  def voice_clone(
152
  prompt_audio,
153
  prompt_text,
@@ -179,7 +190,7 @@ def voice_clone(
179
  return _to_gradio_audio(gen_audio, gen_sr)
180
 
181
 
182
- @spaces.GPU(duration=150)
183
  def voice_design(
184
  instruction,
185
  text,
@@ -203,7 +214,7 @@ def voice_design(
203
  return _to_gradio_audio(gen_audio, gen_sr), (gen_text or "").strip()
204
 
205
 
206
- @spaces.GPU(duration=150)
207
  def semantic_edit(
208
  audio_in,
209
  instruction,
@@ -223,7 +234,7 @@ def semantic_edit(
223
  inference_cfg=float(inference_cfg),
224
  seed=int(seed),
225
  )
226
- return _to_gradio_audio(gen_audio, gen_sr), (gen_text or "").strip()
227
 
228
 
229
  def compose_acoustic_instruction(attribute: str, value: float) -> str:
@@ -236,7 +247,7 @@ def compose_acoustic_instruction(attribute: str, value: float) -> str:
236
  return f"shift the pitch by {steps} step{'' if abs(steps) == 1 else 's'}"
237
 
238
 
239
- @spaces.GPU(duration=150)
240
  def acoustic_edit(
241
  audio_in,
242
  attribute="Speed",
@@ -276,7 +287,7 @@ CSS = """
276
  .dark .gradio-container {color: var(--body-text-color);}
277
  """
278
 
279
- with gr.Blocks(theme=gr.themes.Citrus(), css=CSS, title="FireRedTTS3") as demo:
280
  gr.Markdown(
281
  """
282
  # 🔥 FireRedTTS3 — Unified Speech Generation & Editing
@@ -573,4 +584,4 @@ with gr.Blocks(theme=gr.themes.Citrus(), css=CSS, title="FireRedTTS3") as demo:
573
  )
574
 
575
  if __name__ == "__main__":
576
- demo.queue().launch(mcp_server=True)
 
8
 
9
  import functools
10
  import os
11
+ import re
12
  import urllib.request
13
 
14
  import spaces # noqa: F401 (must precede torch / CUDA imports)
 
135
  return sr, (x * 32767.0).astype(np.int16)
136
 
137
 
138
+ _EDIT_MASK_RE = re.compile(r"<\|edit\|>(?:<\|frame_patch\|>)*<\|end_edit\|>")
139
+
140
+
141
+ def _pretty_edit_text(text: str) -> str:
142
+ """The model marks the re-synthesized span with edit/frame-patch tokens."""
143
+ text = _EDIT_MASK_RE.sub(" ⟨edited span⟩ ", text or "")
144
+ text = re.sub(r"<\|[^|]*\|>", "", text)
145
+ return re.sub(r"\s+", " ", text).strip()
146
+
147
+
148
  def _check_text(text: str, what: str = "Text"):
149
  text = (text or "").strip()
150
  if not text:
 
158
  # --------------------------------------------------------------------------- #
159
  # Inference
160
  # --------------------------------------------------------------------------- #
161
+ @spaces.GPU(duration=60)
162
  def voice_clone(
163
  prompt_audio,
164
  prompt_text,
 
190
  return _to_gradio_audio(gen_audio, gen_sr)
191
 
192
 
193
+ @spaces.GPU(duration=60)
194
  def voice_design(
195
  instruction,
196
  text,
 
214
  return _to_gradio_audio(gen_audio, gen_sr), (gen_text or "").strip()
215
 
216
 
217
+ @spaces.GPU(duration=60)
218
  def semantic_edit(
219
  audio_in,
220
  instruction,
 
234
  inference_cfg=float(inference_cfg),
235
  seed=int(seed),
236
  )
237
+ return _to_gradio_audio(gen_audio, gen_sr), _pretty_edit_text(gen_text)
238
 
239
 
240
  def compose_acoustic_instruction(attribute: str, value: float) -> str:
 
247
  return f"shift the pitch by {steps} step{'' if abs(steps) == 1 else 's'}"
248
 
249
 
250
+ @spaces.GPU(duration=60)
251
  def acoustic_edit(
252
  audio_in,
253
  attribute="Speed",
 
287
  .dark .gradio-container {color: var(--body-text-color);}
288
  """
289
 
290
+ with gr.Blocks(title="FireRedTTS3") as demo:
291
  gr.Markdown(
292
  """
293
  # 🔥 FireRedTTS3 — Unified Speech Generation & Editing
 
584
  )
585
 
586
  if __name__ == "__main__":
587
+ demo.queue().launch(theme=gr.themes.Citrus(), css=CSS, mcp_server=True)