Spaces:
Sleeping
Sleeping
| # | |
| # SPDX-FileCopyrightText: Hadad <hadad@linuxmail.org> | |
| # SPDX-License-Identifier: Apache-2.0 | |
| # | |
| import gradio as gr | |
| from config import VOICE_MODE_PRESET, DEFAULT_VOICE | |
| from ..validation.text import validate_text_input | |
| def switch_to_generating_state(ui_state): | |
| new_state = {"generating": True} | |
| return ( | |
| gr.update(visible=False), | |
| gr.update(visible=True, interactive=True), | |
| gr.update(visible=False), | |
| new_state | |
| ) | |
| def switch_to_idle_state(text_content, ui_state): | |
| new_state = {"generating": False} | |
| has_text_content = bool(text_content and text_content.strip()) | |
| should_show_clear = has_text_content | |
| is_valid_text, _ = validate_text_input(text_content) | |
| return ( | |
| gr.update(visible=True, interactive=is_valid_text), | |
| gr.update(visible=False), | |
| gr.update(visible=should_show_clear), | |
| new_state | |
| ) | |
| def perform_clear_action(): | |
| return ( | |
| "", | |
| None, | |
| gr.update(visible=False), | |
| VOICE_MODE_PRESET, | |
| DEFAULT_VOICE, | |
| None | |
| ) | |
| def create_example_handler(example_text, example_voice): | |
| def set_example_values(): | |
| return example_text, VOICE_MODE_PRESET, example_voice | |
| return set_example_values | |
| def format_example_button_label(example_text, example_voice, max_text_length=40): | |
| truncated_text = ( | |
| example_text[:max_text_length] + "..." | |
| if len(example_text) > max_text_length | |
| else example_text | |
| ) | |
| return f"[{example_voice}] {truncated_text}" |