Spaces:
Running
Running
zach
commited on
Commit
·
0437219
1
Parent(s):
1a6c67a
Fix styling of results components in UI
Browse files- src/app.py +27 -55
src/app.py
CHANGED
|
@@ -157,11 +157,9 @@ class App:
|
|
| 157 |
except ElevenLabsError as ee:
|
| 158 |
logger.error(f"ElevenLabsError while synthesizing speech from text: {ee!s}")
|
| 159 |
raise gr.Error(f'There was an issue communicating with the Elevenlabs API: "{ee.message}"')
|
| 160 |
-
|
| 161 |
except HumeError as he:
|
| 162 |
logger.error(f"HumeError while synthesizing speech from text: {he!s}")
|
| 163 |
raise gr.Error(f'There was an issue communicating with the Hume API: "{he.message}"')
|
| 164 |
-
|
| 165 |
except Exception as e:
|
| 166 |
logger.error(f"Unexpected error during TTS generation: {e}")
|
| 167 |
raise gr.Error("An unexpected error occurred. Please try again later.")
|
|
@@ -222,7 +220,7 @@ class App:
|
|
| 222 |
)
|
| 223 |
)
|
| 224 |
|
| 225 |
-
# Build button text
|
| 226 |
selected_label = f"{selected_provider} {constants.TROPHY_EMOJI}"
|
| 227 |
other_label = f"{other_provider}"
|
| 228 |
|
|
@@ -249,8 +247,8 @@ class App:
|
|
| 249 |
|
| 250 |
Returns:
|
| 251 |
Tuple containing updates for:
|
| 252 |
-
|
| 253 |
-
|
| 254 |
"""
|
| 255 |
import random
|
| 256 |
|
|
@@ -335,8 +333,8 @@ class App:
|
|
| 335 |
gr.update(value=None, autoplay=False), # clear audio player B
|
| 336 |
gr.update(visible=True, interactive=False), # show vote button A
|
| 337 |
gr.update(visible=True, interactive=False), # show vote button B
|
| 338 |
-
gr.update(visible=False), # hide vote result A
|
| 339 |
-
gr.update(visible=False), # hide vote result B
|
| 340 |
default_option_map, # Reset option_map_state as a default OptionMap
|
| 341 |
False, # Reset vote_submitted_state
|
| 342 |
)
|
|
@@ -379,7 +377,7 @@ class App:
|
|
| 379 |
)
|
| 380 |
return (title, randomize_all_button, instructions)
|
| 381 |
|
| 382 |
-
def _build_input_section(self) -> Tuple[gr.Dropdown, gr.Textbox, gr.Button]:
|
| 383 |
"""
|
| 384 |
Builds the input section including the sample character description dropdown, character
|
| 385 |
description input, and generate text button.
|
|
@@ -400,25 +398,6 @@ class App:
|
|
| 400 |
show_copy_button=True,
|
| 401 |
)
|
| 402 |
generate_text_button = gr.Button("Generate Text", variant="secondary")
|
| 403 |
-
return (
|
| 404 |
-
sample_character_description_dropdown,
|
| 405 |
-
character_description_input,
|
| 406 |
-
generate_text_button,
|
| 407 |
-
)
|
| 408 |
-
|
| 409 |
-
def _build_output_section(self) -> Tuple[
|
| 410 |
-
gr.Textbox,
|
| 411 |
-
gr.Button,
|
| 412 |
-
gr.Audio,
|
| 413 |
-
gr.Audio,
|
| 414 |
-
gr.Button,
|
| 415 |
-
gr.Button,
|
| 416 |
-
gr.Textbox,
|
| 417 |
-
gr.Textbox,
|
| 418 |
-
]:
|
| 419 |
-
"""
|
| 420 |
-
Builds the output section including text input, audio players, vote buttons, and vote result displays.
|
| 421 |
-
"""
|
| 422 |
with gr.Group():
|
| 423 |
text_input = gr.Textbox(
|
| 424 |
label="Input Text",
|
|
@@ -431,6 +410,18 @@ class App:
|
|
| 431 |
show_copy_button=True,
|
| 432 |
)
|
| 433 |
synthesize_speech_button = gr.Button("Synthesize Speech", variant="primary")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 434 |
|
| 435 |
with gr.Row(equal_height=True):
|
| 436 |
with gr.Column():
|
|
@@ -440,12 +431,8 @@ class App:
|
|
| 440 |
type="filepath",
|
| 441 |
interactive=False,
|
| 442 |
)
|
| 443 |
-
vote_button_a = gr.Button(
|
| 444 |
-
constants.SELECT_OPTION_A,
|
| 445 |
-
interactive=False,
|
| 446 |
-
)
|
| 447 |
vote_result_a = gr.Textbox(
|
| 448 |
-
label="",
|
| 449 |
interactive=False,
|
| 450 |
visible=False,
|
| 451 |
elem_id="vote-result-a",
|
|
@@ -459,22 +446,15 @@ class App:
|
|
| 459 |
type="filepath",
|
| 460 |
interactive=False,
|
| 461 |
)
|
| 462 |
-
vote_button_b = gr.Button(
|
| 463 |
-
constants.SELECT_OPTION_B,
|
| 464 |
-
interactive=False,
|
| 465 |
-
)
|
| 466 |
vote_result_b = gr.Textbox(
|
| 467 |
-
label="",
|
| 468 |
interactive=False,
|
| 469 |
visible=False,
|
| 470 |
elem_id="vote-result-b",
|
| 471 |
text_align="center",
|
| 472 |
container=False,
|
| 473 |
)
|
| 474 |
-
|
| 475 |
return (
|
| 476 |
-
text_input,
|
| 477 |
-
synthesize_speech_button,
|
| 478 |
option_a_audio_player,
|
| 479 |
option_b_audio_player,
|
| 480 |
vote_button_a,
|
|
@@ -502,13 +482,13 @@ class App:
|
|
| 502 |
instructions,
|
| 503 |
) = self._build_heading_section()
|
| 504 |
(
|
|
|
|
|
|
|
| 505 |
sample_character_description_dropdown,
|
| 506 |
character_description_input,
|
| 507 |
generate_text_button,
|
| 508 |
) = self._build_input_section()
|
| 509 |
(
|
| 510 |
-
text_input,
|
| 511 |
-
synthesize_speech_button,
|
| 512 |
option_a_audio_player,
|
| 513 |
option_b_audio_player,
|
| 514 |
vote_button_a,
|
|
@@ -541,10 +521,7 @@ class App:
|
|
| 541 |
randomize_all_button.click(
|
| 542 |
fn=self._randomize_character_description,
|
| 543 |
inputs=[],
|
| 544 |
-
outputs=[
|
| 545 |
-
sample_character_description_dropdown,
|
| 546 |
-
character_description_input,
|
| 547 |
-
],
|
| 548 |
).then(
|
| 549 |
fn=self._disable_ui,
|
| 550 |
inputs=[],
|
|
@@ -705,12 +682,9 @@ class App:
|
|
| 705 |
],
|
| 706 |
)
|
| 707 |
|
| 708 |
-
#
|
| 709 |
vote_button_a.click(
|
| 710 |
-
fn=lambda _=None: (
|
| 711 |
-
gr.update(interactive=False),
|
| 712 |
-
gr.update(interactive=False),
|
| 713 |
-
),
|
| 714 |
inputs=[],
|
| 715 |
outputs=[vote_button_a, vote_button_b],
|
| 716 |
).then(
|
|
@@ -733,11 +707,9 @@ class App:
|
|
| 733 |
],
|
| 734 |
)
|
| 735 |
|
|
|
|
| 736 |
vote_button_b.click(
|
| 737 |
-
fn=lambda _=None: (
|
| 738 |
-
gr.update(interactive=False),
|
| 739 |
-
gr.update(interactive=False),
|
| 740 |
-
),
|
| 741 |
inputs=[],
|
| 742 |
outputs=[vote_button_a, vote_button_b],
|
| 743 |
).then(
|
|
|
|
| 157 |
except ElevenLabsError as ee:
|
| 158 |
logger.error(f"ElevenLabsError while synthesizing speech from text: {ee!s}")
|
| 159 |
raise gr.Error(f'There was an issue communicating with the Elevenlabs API: "{ee.message}"')
|
|
|
|
| 160 |
except HumeError as he:
|
| 161 |
logger.error(f"HumeError while synthesizing speech from text: {he!s}")
|
| 162 |
raise gr.Error(f'There was an issue communicating with the Hume API: "{he.message}"')
|
|
|
|
| 163 |
except Exception as e:
|
| 164 |
logger.error(f"Unexpected error during TTS generation: {e}")
|
| 165 |
raise gr.Error("An unexpected error occurred. Please try again later.")
|
|
|
|
| 220 |
)
|
| 221 |
)
|
| 222 |
|
| 223 |
+
# Build button text to display results
|
| 224 |
selected_label = f"{selected_provider} {constants.TROPHY_EMOJI}"
|
| 225 |
other_label = f"{other_provider}"
|
| 226 |
|
|
|
|
| 247 |
|
| 248 |
Returns:
|
| 249 |
Tuple containing updates for:
|
| 250 |
+
- sample_character_description_dropdown (select random)
|
| 251 |
+
- character_description_input (update value)
|
| 252 |
"""
|
| 253 |
import random
|
| 254 |
|
|
|
|
| 333 |
gr.update(value=None, autoplay=False), # clear audio player B
|
| 334 |
gr.update(visible=True, interactive=False), # show vote button A
|
| 335 |
gr.update(visible=True, interactive=False), # show vote button B
|
| 336 |
+
gr.update(visible=False, elem_classes=None), # hide vote result A and clear custom styling
|
| 337 |
+
gr.update(visible=False, elem_classes=None), # hide vote result B and clear custom styling
|
| 338 |
default_option_map, # Reset option_map_state as a default OptionMap
|
| 339 |
False, # Reset vote_submitted_state
|
| 340 |
)
|
|
|
|
| 377 |
)
|
| 378 |
return (title, randomize_all_button, instructions)
|
| 379 |
|
| 380 |
+
def _build_input_section(self) -> Tuple[gr.Dropdown, gr.Textbox, gr.Button, gr.Textbox, gr.Button]:
|
| 381 |
"""
|
| 382 |
Builds the input section including the sample character description dropdown, character
|
| 383 |
description input, and generate text button.
|
|
|
|
| 398 |
show_copy_button=True,
|
| 399 |
)
|
| 400 |
generate_text_button = gr.Button("Generate Text", variant="secondary")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 401 |
with gr.Group():
|
| 402 |
text_input = gr.Textbox(
|
| 403 |
label="Input Text",
|
|
|
|
| 410 |
show_copy_button=True,
|
| 411 |
)
|
| 412 |
synthesize_speech_button = gr.Button("Synthesize Speech", variant="primary")
|
| 413 |
+
return (
|
| 414 |
+
text_input,
|
| 415 |
+
synthesize_speech_button,
|
| 416 |
+
sample_character_description_dropdown,
|
| 417 |
+
character_description_input,
|
| 418 |
+
generate_text_button,
|
| 419 |
+
)
|
| 420 |
+
|
| 421 |
+
def _build_output_section(self) -> Tuple[gr.Audio, gr.Audio, gr.Button, gr.Button, gr.Textbox, gr.Textbox]:
|
| 422 |
+
"""
|
| 423 |
+
Builds the output section including text input, audio players, vote buttons, and vote result displays.
|
| 424 |
+
"""
|
| 425 |
|
| 426 |
with gr.Row(equal_height=True):
|
| 427 |
with gr.Column():
|
|
|
|
| 431 |
type="filepath",
|
| 432 |
interactive=False,
|
| 433 |
)
|
| 434 |
+
vote_button_a = gr.Button(constants.SELECT_OPTION_A, interactive=False)
|
|
|
|
|
|
|
|
|
|
| 435 |
vote_result_a = gr.Textbox(
|
|
|
|
| 436 |
interactive=False,
|
| 437 |
visible=False,
|
| 438 |
elem_id="vote-result-a",
|
|
|
|
| 446 |
type="filepath",
|
| 447 |
interactive=False,
|
| 448 |
)
|
| 449 |
+
vote_button_b = gr.Button(constants.SELECT_OPTION_B, interactive=False)
|
|
|
|
|
|
|
|
|
|
| 450 |
vote_result_b = gr.Textbox(
|
|
|
|
| 451 |
interactive=False,
|
| 452 |
visible=False,
|
| 453 |
elem_id="vote-result-b",
|
| 454 |
text_align="center",
|
| 455 |
container=False,
|
| 456 |
)
|
|
|
|
| 457 |
return (
|
|
|
|
|
|
|
| 458 |
option_a_audio_player,
|
| 459 |
option_b_audio_player,
|
| 460 |
vote_button_a,
|
|
|
|
| 482 |
instructions,
|
| 483 |
) = self._build_heading_section()
|
| 484 |
(
|
| 485 |
+
text_input,
|
| 486 |
+
synthesize_speech_button,
|
| 487 |
sample_character_description_dropdown,
|
| 488 |
character_description_input,
|
| 489 |
generate_text_button,
|
| 490 |
) = self._build_input_section()
|
| 491 |
(
|
|
|
|
|
|
|
| 492 |
option_a_audio_player,
|
| 493 |
option_b_audio_player,
|
| 494 |
vote_button_a,
|
|
|
|
| 521 |
randomize_all_button.click(
|
| 522 |
fn=self._randomize_character_description,
|
| 523 |
inputs=[],
|
| 524 |
+
outputs=[sample_character_description_dropdown, character_description_input],
|
|
|
|
|
|
|
|
|
|
| 525 |
).then(
|
| 526 |
fn=self._disable_ui,
|
| 527 |
inputs=[],
|
|
|
|
| 682 |
],
|
| 683 |
)
|
| 684 |
|
| 685 |
+
# Handle Option A vote
|
| 686 |
vote_button_a.click(
|
| 687 |
+
fn=lambda _=None: (gr.update(interactive=False), gr.update(interactive=False)),
|
|
|
|
|
|
|
|
|
|
| 688 |
inputs=[],
|
| 689 |
outputs=[vote_button_a, vote_button_b],
|
| 690 |
).then(
|
|
|
|
| 707 |
],
|
| 708 |
)
|
| 709 |
|
| 710 |
+
# Handle Option B vote
|
| 711 |
vote_button_b.click(
|
| 712 |
+
fn=lambda _=None: (gr.update(interactive=False), gr.update(interactive=False)),
|
|
|
|
|
|
|
|
|
|
| 713 |
inputs=[],
|
| 714 |
outputs=[vote_button_a, vote_button_b],
|
| 715 |
).then(
|