File size: 4,750 Bytes
c383152
 
 
efd0da0
c383152
 
 
 
 
6d00bb0
 
 
 
efd0da0
 
 
6d00bb0
 
 
f5ced5e
6d00bb0
 
 
 
 
 
 
c383152
6d00bb0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c383152
efd0da0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c383152
 
 
 
 
efd0da0
 
 
f5ced5e
 
 
 
c383152
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f5ced5e
 
 
 
 
 
 
 
c383152
 
 
 
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import gradio as gr
from i18n import get_text

def create_welcome_tab(initial_lang: str, tabs: gr.Tabs):
    """
    Creates the UI components for the Welcome Tab.
    Returns a dictionary of all component handles that need dynamic updates.
    """
    with gr.TabItem(get_text("welcome_tab_title", initial_lang)) as welcome_tab:
        with gr.Column(elem_classes=["welcome-content"], scale=1):
            welcome_header_md = gr.Markdown(f"# {get_text('welcome_header', initial_lang)}")
            welcome_desc_md = gr.Markdown(get_text('welcome_description', initial_lang))
            with gr.Row(equal_height=True):
                welcome_chat_desc_btn = gr.Button(get_text('welcome_chat_desc', initial_lang))
                welcome_code_desc_btn = gr.Button(get_text('welcome_code_desc', initial_lang))
                welcome_writer_desc_btn = gr.Button(get_text('welcome_writer_desc', initial_lang))
            
            gr.Markdown(" ")
            welcome_model_links_header_md = gr.Markdown(get_text('welcome_model_links_header', initial_lang))

            with gr.Row(equal_height=True):    
                welcome_hf_link_md = gr.Markdown(get_text('welcome_hf_link', initial_lang), padding=True, container=True)
                welcome_hf_report_md = gr.Markdown(get_text('welcome_hf_report', initial_lang), padding=True, container=True)
                welcome_x_account_md = gr.Markdown(get_text('welcome_x_account', initial_lang), padding=True, container=True)
            
            gr.Markdown(" ")
            welcome_lang_select_md = gr.Markdown(get_text('welcome_select_language', initial_lang))
            
            with gr.Row():
                with gr.Column(elem_classes=["language-buttons"]):
                    en_button = gr.Button(get_text('lang_en', initial_lang))
                    zh_button = gr.Button(get_text('lang_zh', initial_lang))
        
        en_button.click(
            fn=None,
            inputs=[],
            js="() => { window.dispatchEvent(new CustomEvent('langChange.SpaceApp', { detail: { lang: 'en' } })); }"
        )
        zh_button.click(
            fn=None,
            inputs=[],
            js="() => { window.dispatchEvent(new CustomEvent('langChange.SpaceApp', { detail: { lang: 'zh' } })); }"
        )

        welcome_chat_desc_btn.click(
            fn=lambda: gr.Tabs(selected="chat"),
            inputs=[],
            outputs=[tabs]
        )

        welcome_code_desc_btn.click(
            fn=lambda: gr.Tabs(selected="code"),
            inputs=[],
            outputs=[tabs]
        )

        welcome_writer_desc_btn.click(
            fn=lambda: gr.Tabs(selected="writer"),
            inputs=[],
            outputs=[tabs]
        )

    # Return a dictionary for easier access in app.py
    components = {
        "tab": welcome_tab,
        "header": welcome_header_md,
        "description": welcome_desc_md,
        "chat_description": welcome_chat_desc_btn,
        "code_description": welcome_code_desc_btn,
        "writer_description": welcome_writer_desc_btn,
        "model_links_header": welcome_model_links_header_md,
        "hf_link": welcome_hf_link_md,
        "hf_report": welcome_hf_report_md,
        "x_account": welcome_x_account_md,
        "lang_select_header": welcome_lang_select_md,
        "en_button": en_button,
        "zh_button": zh_button
    }
    
    return components

def update_language(lang: str, components: dict):
    """
    Returns a dictionary mapping components to their gr.update calls.
    """
    updates = {
        components["tab"]: gr.update(label=get_text("welcome_tab_title", lang)),
        components["header"]: gr.update(value=f"# {get_text('welcome_header', lang)}"),
        components["description"]: gr.update(value=get_text('welcome_description', lang)),
        components["chat_description"]: gr.update(value=get_text('welcome_chat_desc', lang)),
        components["code_description"]: gr.update(value=get_text('welcome_code_desc', lang)),
        components["writer_description"]: gr.update(value=get_text('welcome_writer_desc', lang)),
        components["model_links_header"]: gr.update(value=get_text('welcome_model_links_header', lang)),
        components["hf_link"]: gr.update(value=get_text('welcome_hf_link', lang)),
        components["hf_report"]: gr.update(value=get_text('welcome_hf_report', lang)),
        components["x_account"]: gr.update(value=get_text('welcome_x_account', lang)),
        components["lang_select_header"]: gr.update(value=get_text('welcome_select_language', lang)),
        components["en_button"]: gr.update(value=get_text('lang_en', lang)),
        components["zh_button"]: gr.update(value=get_text('lang_zh', lang)),
    }
    return updates