File size: 1,460 Bytes
5da0109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#
# 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)