Spaces:
Running
Running
| 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"} | |
| ] | |
| ) |