Spaces:
Running
Running
Commit
·
c9b7b18
1
Parent(s):
033e87b
added counter and name
Browse files
app.py
CHANGED
|
@@ -282,9 +282,6 @@ with gr.Blocks(
|
|
| 282 |
"- Special thanks to [@jeremylee12](https://huggingface.co/jeremylee12) for his contributions"
|
| 283 |
)
|
| 284 |
|
| 285 |
-
# State variable for generation counter
|
| 286 |
-
gen_count_state = gr.State(value=initial_counter)
|
| 287 |
-
|
| 288 |
# Event Handlers
|
| 289 |
def update_char_count(text):
|
| 290 |
"""Update character count as user types"""
|
|
@@ -300,7 +297,7 @@ with gr.Blocks(
|
|
| 300 |
"""Clear text input"""
|
| 301 |
return "", "**Character count:** 0 / 500"
|
| 302 |
|
| 303 |
-
def on_generate(text, voice_display
|
| 304 |
voice_id = voice_choices.get(voice_display)
|
| 305 |
audio_url, _status, t_time, rtf, wav_dur, voc_time, no_voc_time, rtf_no_voc = (
|
| 306 |
synthesize_speech(text, voice_id)
|
|
@@ -308,7 +305,8 @@ with gr.Blocks(
|
|
| 308 |
|
| 309 |
# Download audio if URL is available
|
| 310 |
audio_file = None
|
| 311 |
-
|
|
|
|
| 312 |
if audio_url:
|
| 313 |
try:
|
| 314 |
audio_response = requests.get(audio_url, timeout=30)
|
|
@@ -342,8 +340,7 @@ with gr.Blocks(
|
|
| 342 |
audio_file,
|
| 343 |
gr.update(visible=has_metrics),
|
| 344 |
gr.update(value=metrics_json, visible=has_metrics),
|
| 345 |
-
new_count,
|
| 346 |
-
f"**Generations:** {new_count} 🌍",
|
| 347 |
)
|
| 348 |
|
| 349 |
# Update character count on text input change
|
|
@@ -370,13 +367,12 @@ with gr.Blocks(
|
|
| 370 |
|
| 371 |
generate_btn.click(
|
| 372 |
fn=on_generate,
|
| 373 |
-
inputs=[text_input, voice_dropdown
|
| 374 |
outputs=[
|
| 375 |
audio_output,
|
| 376 |
# status_output,
|
| 377 |
metrics_header,
|
| 378 |
metrics_output,
|
| 379 |
-
gen_count_state,
|
| 380 |
generation_counter,
|
| 381 |
],
|
| 382 |
)
|
|
|
|
| 282 |
"- Special thanks to [@jeremylee12](https://huggingface.co/jeremylee12) for his contributions"
|
| 283 |
)
|
| 284 |
|
|
|
|
|
|
|
|
|
|
| 285 |
# Event Handlers
|
| 286 |
def update_char_count(text):
|
| 287 |
"""Update character count as user types"""
|
|
|
|
| 297 |
"""Clear text input"""
|
| 298 |
return "", "**Character count:** 0 / 500"
|
| 299 |
|
| 300 |
+
def on_generate(text, voice_display):
|
| 301 |
voice_id = voice_choices.get(voice_display)
|
| 302 |
audio_url, _status, t_time, rtf, wav_dur, voc_time, no_voc_time, rtf_no_voc = (
|
| 303 |
synthesize_speech(text, voice_id)
|
|
|
|
| 305 |
|
| 306 |
# Download audio if URL is available
|
| 307 |
audio_file = None
|
| 308 |
+
# Always get fresh counter from file
|
| 309 |
+
new_count = load_counter()
|
| 310 |
if audio_url:
|
| 311 |
try:
|
| 312 |
audio_response = requests.get(audio_url, timeout=30)
|
|
|
|
| 340 |
audio_file,
|
| 341 |
gr.update(visible=has_metrics),
|
| 342 |
gr.update(value=metrics_json, visible=has_metrics),
|
| 343 |
+
f"**🌍 Generations:** {new_count}",
|
|
|
|
| 344 |
)
|
| 345 |
|
| 346 |
# Update character count on text input change
|
|
|
|
| 367 |
|
| 368 |
generate_btn.click(
|
| 369 |
fn=on_generate,
|
| 370 |
+
inputs=[text_input, voice_dropdown],
|
| 371 |
outputs=[
|
| 372 |
audio_output,
|
| 373 |
# status_output,
|
| 374 |
metrics_header,
|
| 375 |
metrics_output,
|
|
|
|
| 376 |
generation_counter,
|
| 377 |
],
|
| 378 |
)
|