Spaces:
Running
on
Zero
Running
on
Zero
Add input validation and examples
Browse files- .gitattributes +2 -0
- app.py +48 -7
- assets/app/female.wav +3 -0
- assets/app/male.wav +3 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
assets/app/male.wav filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
assets/app/female.wav filter=lfs diff=lfs merge=lfs -text
|
app.py
CHANGED
|
@@ -96,7 +96,7 @@ def main():
|
|
| 96 |
prompt_text = gr.Textbox(
|
| 97 |
lines=3,
|
| 98 |
max_length=config.max_prompt_chars,
|
| 99 |
-
label=f"Prompt transcript
|
| 100 |
placeholder="Text that matches the prompt audio",
|
| 101 |
)
|
| 102 |
|
|
@@ -104,7 +104,7 @@ def main():
|
|
| 104 |
target_text = gr.Textbox(
|
| 105 |
lines=3,
|
| 106 |
max_length=config.max_phone_tokens,
|
| 107 |
-
label=f"Target text
|
| 108 |
placeholder="What you want the model to say",
|
| 109 |
)
|
| 110 |
output_audio = gr.Audio(
|
|
@@ -116,19 +116,60 @@ def main():
|
|
| 116 |
with gr.Row():
|
| 117 |
clear_btn = gr.Button("Clear", elem_id="clear", variant="secondary")
|
| 118 |
submit_btn = gr.Button("Submit", elem_id="submit", variant="primary")
|
| 119 |
-
|
| 120 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
submit_btn.click(
|
| 122 |
fn=synthesize_fn,
|
| 123 |
inputs=[prompt_audio, prompt_text, target_text],
|
| 124 |
outputs=output_audio,
|
| 125 |
)
|
| 126 |
|
| 127 |
-
# reset everything
|
| 128 |
clear_btn.click(
|
| 129 |
-
fn=lambda: (None, "", "", None),
|
| 130 |
inputs=[],
|
| 131 |
-
outputs=[prompt_audio, prompt_text, target_text, output_audio],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 132 |
)
|
| 133 |
|
| 134 |
demo.launch()
|
|
|
|
| 96 |
prompt_text = gr.Textbox(
|
| 97 |
lines=3,
|
| 98 |
max_length=config.max_prompt_chars,
|
| 99 |
+
label=f"Prompt transcript (Required, max {config.max_prompt_chars} chars)",
|
| 100 |
placeholder="Text that matches the prompt audio",
|
| 101 |
)
|
| 102 |
|
|
|
|
| 104 |
target_text = gr.Textbox(
|
| 105 |
lines=3,
|
| 106 |
max_length=config.max_phone_tokens,
|
| 107 |
+
label=f"Target text (Required, max {config.max_phone_tokens} chars)",
|
| 108 |
placeholder="What you want the model to say",
|
| 109 |
)
|
| 110 |
output_audio = gr.Audio(
|
|
|
|
| 116 |
with gr.Row():
|
| 117 |
clear_btn = gr.Button("Clear", elem_id="clear", variant="secondary")
|
| 118 |
submit_btn = gr.Button("Submit", elem_id="submit", variant="primary")
|
| 119 |
+
|
| 120 |
+
# Message box for validation errors
|
| 121 |
+
validation_msg = gr.Markdown("", visible=False)
|
| 122 |
+
|
| 123 |
+
# --- Validation logic ---
|
| 124 |
+
def validate_inputs(audio, ptext, ttext):
|
| 125 |
+
if not audio:
|
| 126 |
+
return gr.update(visible=True, value="⚠️ Please provide a prompt audio."), gr.update(interactive=False)
|
| 127 |
+
if not ptext.strip():
|
| 128 |
+
return gr.update(visible=True, value="⚠️ Please provide a prompt transcript."), gr.update(interactive=False)
|
| 129 |
+
if not ttext.strip():
|
| 130 |
+
return gr.update(visible=True, value="⚠️ Please provide target text."), gr.update(interactive=False)
|
| 131 |
+
return gr.update(visible=False, value=""), gr.update(interactive=True)
|
| 132 |
+
|
| 133 |
+
# Live validation whenever inputs change
|
| 134 |
+
for inp in [prompt_audio, prompt_text, target_text]:
|
| 135 |
+
inp.change(
|
| 136 |
+
fn=validate_inputs,
|
| 137 |
+
inputs=[prompt_audio, prompt_text, target_text],
|
| 138 |
+
outputs=[validation_msg, submit_btn],
|
| 139 |
+
)
|
| 140 |
+
|
| 141 |
+
# --- Wire up actions ---
|
| 142 |
submit_btn.click(
|
| 143 |
fn=synthesize_fn,
|
| 144 |
inputs=[prompt_audio, prompt_text, target_text],
|
| 145 |
outputs=output_audio,
|
| 146 |
)
|
| 147 |
|
|
|
|
| 148 |
clear_btn.click(
|
| 149 |
+
fn=lambda: (None, "", "", None, gr.update(visible=False, value=""), gr.update(interactive=False)),
|
| 150 |
inputs=[],
|
| 151 |
+
outputs=[prompt_audio, prompt_text, target_text, output_audio, validation_msg, submit_btn],
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
# --- Add Examples ---
|
| 155 |
+
gr.Markdown("### Examples")
|
| 156 |
+
gr.Examples(
|
| 157 |
+
examples=[
|
| 158 |
+
[
|
| 159 |
+
"assets/app/male.wav",
|
| 160 |
+
"You could take the easy route or a situation that makes sense which a lot of you do",
|
| 161 |
+
"Hey, how are you doing? I just uhm want to make sure everything is okay."
|
| 162 |
+
],
|
| 163 |
+
[
|
| 164 |
+
"assets/app/female.wav",
|
| 165 |
+
"I would certainly anticipate some pushback whereas most people know if you followed my work.",
|
| 166 |
+
"Hello, hello. Let's have a quick chat, uh, in an hour. I need to share something with you."
|
| 167 |
+
],
|
| 168 |
+
],
|
| 169 |
+
inputs=[prompt_audio, prompt_text, target_text],
|
| 170 |
+
outputs=output_audio,
|
| 171 |
+
fn=synthesize_fn,
|
| 172 |
+
cache_examples=True,
|
| 173 |
)
|
| 174 |
|
| 175 |
demo.launch()
|
assets/app/female.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:11b998e35bb346f7512c6ceef1ea343cc2f612fe6ee25e2028d05ff52651a8b0
|
| 3 |
+
size 228716
|
assets/app/male.wav
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b3e2776fb252ad6794107493531e5d1854c8ca1ae9df4feabfb19746bc1cc702
|
| 3 |
+
size 225644
|