File size: 3,774 Bytes
49928ee
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import gradio as gr

def greet(name):
    """Greet the user with the provided name."""
    return f"Привет, {name}! Добро пожаловать в Gradio 6! 🎉"

def count_characters(text):
    """Count the number of characters in the text."""
    return len(text)

def reverse_text(text):
    """Reverse the input text."""
    return text[::-1]

with gr.Blocks() as demo:
    """Gradio 6 application with modern Soft theme."""
    gr.Markdown(
        """
        # 🎉 Привет!
        
        Welcome to a modern Gradio 6 application with beautiful UI.
        
        This demo showcases Gradio 6's new features including:
        - Modern Soft theme
        - Responsive layout
        - Interactive components
        """
    )
    
    with gr.Row():
        with gr.Column(scale=1):
            gr.Markdown("### Input")
            name_input = gr.Textbox(
                label="Введите ваше имя (Enter your name)",
                placeholder="Привет, мир!",
                lines=2,
                elem_classes="input-box"
            )
            
            character_count = gr.Number(
                label="Количество символов (Character count)",
                value=0,
                interactive=False,
                elem_classes="count-box"
            )
            
        with gr.Column(scale=1):
            gr.Markdown("### Output")
            greet_output = gr.Textbox(
                label="Приветствие (Greeting)",
                lines=2,
                interactive=False,
                elem_classes="output-box"
            )
            
            reverse_output = gr.Textbox(
                label="Реверс текста (Text reverse)",
                lines=2,
                interactive=False,
                elem_classes="output-box"
            )
    
    # Button to trigger actions
    action_btn = gr.Button(
        "Отправить / Submit",
        variant="primary",
        size="lg",
        elem_classes="action-button"
    )
    
    # Clear button
    clear_btn = gr.Button(
        "Очистить / Clear",
        variant="secondary",
        elem_classes="clear-button"
    )
    
    # Examples section
    gr.Examples(
        examples=[
            ["Алина", "Привет, Алина!"],
            ["Мир", "Привет, Мир!"],
            ["Программирование", "Привет, Программирование!"],
        ],
        inputs=name_input,
        label="Примеры (Examples)"
    )

# Event listeners using Gradio 6 syntax with api_visibility
action_btn.click(
    fn=greet,
    inputs=[name_input],
    outputs=[greet_output],
    api_visibility="public"
)

name_input.change(
    fn=count_characters,
    inputs=[name_input],
    outputs=[character_count],
    api_visibility="public"
)

name_input.change(
    fn=reverse_text,
    inputs=[name_input],
    outputs=[reverse_output],
    api_visibility="public"
)

clear_btn.click(
    fn=lambda: "",
    inputs=None,
    outputs=[name_input, greet_output, character_count, reverse_output],
    api_visibility="public"
)

# Launch the application with modern theme and footer
demo.launch(
    theme=gr.themes.Soft(
        primary_hue="blue",
        secondary_hue="indigo",
        neutral_hue="slate",
        font=gr.themes.GoogleFont("Inter"),
        text_size="lg",
        spacing_size="lg",
        radius_size="md"
    ).set(
        button_primary_background_fill="*primary_600",
        button_primary_background_fill_hover="*primary_700",
        block_title_text_weight="600",
    ),
    footer_links=[
        {"label": "Built with anycoder", "url": "https://huggingface.co/spaces/akhaliq/anycoder"}
    ]
)