Spaces:
Sleeping
Sleeping
| # | |
| # SPDX-FileCopyrightText: Hadad <hadad@linuxmail.org> | |
| # SPDX-License-Identifier: Apache-2.0 | |
| # | |
| import gradio as gr | |
| from config import MAXIMUM_INPUT_LENGTH, VOICE_MODE_CLONE | |
| from ..validation.text import validate_text_input | |
| def check_generate_button_state(text_content, ui_state): | |
| if ui_state.get("generating", False): | |
| return gr.update(interactive=False) | |
| is_valid, _ = validate_text_input(text_content) | |
| return gr.update(interactive=is_valid) | |
| def calculate_character_count_display(text_content): | |
| character_count = len(text_content) if text_content else 0 | |
| display_color = ( | |
| "var(--error-text-color)" | |
| if character_count > MAXIMUM_INPUT_LENGTH | |
| else "var(--body-text-color-subdued)" | |
| ) | |
| return f"<div style='text-align: right; padding: 4px 0;'><span style='color: {display_color}; font-size: 0.85em;'>{character_count} / {MAXIMUM_INPUT_LENGTH}</span></div>" | |
| def determine_clear_button_visibility(text_content, ui_state): | |
| if ui_state.get("generating", False): | |
| return gr.update(visible=False) | |
| has_text_content = bool(text_content and text_content.strip()) | |
| should_show_clear = has_text_content | |
| return gr.update(visible=should_show_clear) | |
| def update_voice_mode_visibility(voice_mode_value): | |
| if voice_mode_value == VOICE_MODE_CLONE: | |
| return gr.update(visible=False), gr.update(visible=True) | |
| else: | |
| return gr.update(visible=True), gr.update(visible=False) |