Ivan1008 commited on
Commit
49928ee
·
verified ·
1 Parent(s): 9d861ad

Update app.py from anycoder

Browse files
Files changed (1) hide show
  1. app.py +136 -0
app.py ADDED
@@ -0,0 +1,136 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+ def greet(name):
4
+ """Greet the user with the provided name."""
5
+ return f"Привет, {name}! Добро пожаловать в Gradio 6! 🎉"
6
+
7
+ def count_characters(text):
8
+ """Count the number of characters in the text."""
9
+ return len(text)
10
+
11
+ def reverse_text(text):
12
+ """Reverse the input text."""
13
+ return text[::-1]
14
+
15
+ with gr.Blocks() as demo:
16
+ """Gradio 6 application with modern Soft theme."""
17
+ gr.Markdown(
18
+ """
19
+ # 🎉 Привет!
20
+
21
+ Welcome to a modern Gradio 6 application with beautiful UI.
22
+
23
+ This demo showcases Gradio 6's new features including:
24
+ - Modern Soft theme
25
+ - Responsive layout
26
+ - Interactive components
27
+ """
28
+ )
29
+
30
+ with gr.Row():
31
+ with gr.Column(scale=1):
32
+ gr.Markdown("### Input")
33
+ name_input = gr.Textbox(
34
+ label="Введите ваше имя (Enter your name)",
35
+ placeholder="Привет, мир!",
36
+ lines=2,
37
+ elem_classes="input-box"
38
+ )
39
+
40
+ character_count = gr.Number(
41
+ label="Количество символов (Character count)",
42
+ value=0,
43
+ interactive=False,
44
+ elem_classes="count-box"
45
+ )
46
+
47
+ with gr.Column(scale=1):
48
+ gr.Markdown("### Output")
49
+ greet_output = gr.Textbox(
50
+ label="Приветствие (Greeting)",
51
+ lines=2,
52
+ interactive=False,
53
+ elem_classes="output-box"
54
+ )
55
+
56
+ reverse_output = gr.Textbox(
57
+ label="Реверс текста (Text reverse)",
58
+ lines=2,
59
+ interactive=False,
60
+ elem_classes="output-box"
61
+ )
62
+
63
+ # Button to trigger actions
64
+ action_btn = gr.Button(
65
+ "Отправить / Submit",
66
+ variant="primary",
67
+ size="lg",
68
+ elem_classes="action-button"
69
+ )
70
+
71
+ # Clear button
72
+ clear_btn = gr.Button(
73
+ "Очистить / Clear",
74
+ variant="secondary",
75
+ elem_classes="clear-button"
76
+ )
77
+
78
+ # Examples section
79
+ gr.Examples(
80
+ examples=[
81
+ ["Алина", "Привет, Алина!"],
82
+ ["Мир", "Привет, Мир!"],
83
+ ["Программирование", "Привет, Программирование!"],
84
+ ],
85
+ inputs=name_input,
86
+ label="Примеры (Examples)"
87
+ )
88
+
89
+ # Event listeners using Gradio 6 syntax with api_visibility
90
+ action_btn.click(
91
+ fn=greet,
92
+ inputs=[name_input],
93
+ outputs=[greet_output],
94
+ api_visibility="public"
95
+ )
96
+
97
+ name_input.change(
98
+ fn=count_characters,
99
+ inputs=[name_input],
100
+ outputs=[character_count],
101
+ api_visibility="public"
102
+ )
103
+
104
+ name_input.change(
105
+ fn=reverse_text,
106
+ inputs=[name_input],
107
+ outputs=[reverse_output],
108
+ api_visibility="public"
109
+ )
110
+
111
+ clear_btn.click(
112
+ fn=lambda: "",
113
+ inputs=None,
114
+ outputs=[name_input, greet_output, character_count, reverse_output],
115
+ api_visibility="public"
116
+ )
117
+
118
+ # Launch the application with modern theme and footer
119
+ demo.launch(
120
+ theme=gr.themes.Soft(
121
+ primary_hue="blue",
122
+ secondary_hue="indigo",
123
+ neutral_hue="slate",
124
+ font=gr.themes.GoogleFont("Inter"),
125
+ text_size="lg",
126
+ spacing_size="lg",
127
+ radius_size="md"
128
+ ).set(
129
+ button_primary_background_fill="*primary_600",
130
+ button_primary_background_fill_hover="*primary_700",
131
+ block_title_text_weight="600",
132
+ ),
133
+ footer_links=[
134
+ {"label": "Built with anycoder", "url": "https://huggingface.co/spaces/akhaliq/anycoder"}
135
+ ]
136
+ )