Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Commit
·
34c49bb
1
Parent(s):
0e3ad8a
Add duration estimation calculator to UI
Browse files
app.py
CHANGED
|
@@ -225,6 +225,18 @@ def create_demo_interface():
|
|
| 225 |
def update_speaker_visibility(num_speakers):
|
| 226 |
return [gr.update(visible=(i < num_speakers)) for i in range(4)]
|
| 227 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
def smart_speaker_selection(gender_list):
|
| 229 |
"""Select speakers based on gender requirements."""
|
| 230 |
selected = []
|
|
@@ -253,26 +265,35 @@ def create_demo_interface():
|
|
| 253 |
def load_specific_example(idx, natural):
|
| 254 |
"""Load a specific example script."""
|
| 255 |
if idx >= len(EXAMPLE_SCRIPTS):
|
| 256 |
-
return [2, ""] + [None, None, None, None]
|
| 257 |
|
| 258 |
script = EXAMPLE_SCRIPTS_NATURAL[idx] if natural else EXAMPLE_SCRIPTS[idx]
|
| 259 |
genders = SCRIPT_SPEAKER_GENDERS[idx] if idx < len(SCRIPT_SPEAKER_GENDERS) else ["neutral"]
|
| 260 |
speakers = smart_speaker_selection(genders)
|
|
|
|
| 261 |
|
| 262 |
# Pad speakers to 4
|
| 263 |
while len(speakers) < 4:
|
| 264 |
speakers.append(None)
|
| 265 |
|
| 266 |
-
return [len(genders), script] + speakers[:4]
|
| 267 |
|
| 268 |
# Connect example buttons
|
| 269 |
for idx, btn in enumerate(example_buttons):
|
| 270 |
btn.click(
|
| 271 |
fn=lambda nat, i=idx: load_specific_example(i, nat),
|
| 272 |
inputs=[use_natural],
|
| 273 |
-
outputs=[num_speakers, script_input] + speaker_selections,
|
| 274 |
queue=False
|
| 275 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
|
| 277 |
num_speakers.change(
|
| 278 |
fn=update_speaker_visibility,
|
|
|
|
| 225 |
def update_speaker_visibility(num_speakers):
|
| 226 |
return [gr.update(visible=(i < num_speakers)) for i in range(4)]
|
| 227 |
|
| 228 |
+
def estimate_duration(script):
|
| 229 |
+
"""Estimate duration based on word count."""
|
| 230 |
+
if not script:
|
| 231 |
+
return ""
|
| 232 |
+
words = len(script.split())
|
| 233 |
+
# Approximate 150 words per minute for natural speech
|
| 234 |
+
minutes = words / 150
|
| 235 |
+
if minutes < 1:
|
| 236 |
+
return f"~{int(minutes * 60)} seconds"
|
| 237 |
+
else:
|
| 238 |
+
return f"~{minutes:.1f} minutes"
|
| 239 |
+
|
| 240 |
def smart_speaker_selection(gender_list):
|
| 241 |
"""Select speakers based on gender requirements."""
|
| 242 |
selected = []
|
|
|
|
| 265 |
def load_specific_example(idx, natural):
|
| 266 |
"""Load a specific example script."""
|
| 267 |
if idx >= len(EXAMPLE_SCRIPTS):
|
| 268 |
+
return [2, "", ""] + [None, None, None, None]
|
| 269 |
|
| 270 |
script = EXAMPLE_SCRIPTS_NATURAL[idx] if natural else EXAMPLE_SCRIPTS[idx]
|
| 271 |
genders = SCRIPT_SPEAKER_GENDERS[idx] if idx < len(SCRIPT_SPEAKER_GENDERS) else ["neutral"]
|
| 272 |
speakers = smart_speaker_selection(genders)
|
| 273 |
+
duration = estimate_duration(script)
|
| 274 |
|
| 275 |
# Pad speakers to 4
|
| 276 |
while len(speakers) < 4:
|
| 277 |
speakers.append(None)
|
| 278 |
|
| 279 |
+
return [len(genders), script, duration] + speakers[:4]
|
| 280 |
|
| 281 |
# Connect example buttons
|
| 282 |
for idx, btn in enumerate(example_buttons):
|
| 283 |
btn.click(
|
| 284 |
fn=lambda nat, i=idx: load_specific_example(i, nat),
|
| 285 |
inputs=[use_natural],
|
| 286 |
+
outputs=[num_speakers, script_input, duration_display] + speaker_selections,
|
| 287 |
queue=False
|
| 288 |
)
|
| 289 |
+
|
| 290 |
+
# Update duration when script changes
|
| 291 |
+
script_input.change(
|
| 292 |
+
fn=estimate_duration,
|
| 293 |
+
inputs=[script_input],
|
| 294 |
+
outputs=[duration_display],
|
| 295 |
+
queue=False
|
| 296 |
+
)
|
| 297 |
|
| 298 |
num_speakers.change(
|
| 299 |
fn=update_speaker_visibility,
|