Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| import time | |
| from datetime import datetime | |
| def greet(name, language): | |
| if not name: | |
| name = "World" | |
| greetings = { | |
| "English": "Hello", | |
| "Spanish": "¡Hola", | |
| "French": "Bonjour", | |
| "Japanese": "こんにちは", | |
| "German": "Hallo" | |
| } | |
| # Get current time | |
| current_time = datetime.now().strftime("%H:%M:%S") | |
| # Add a small delay for animation effect | |
| time.sleep(0.5) | |
| greeting = greetings.get(language, "Hello") | |
| message = f""" | |
| <div style='text-align: center; animation: fadeIn 1s;'> | |
| <h1 style='color: #2E86C1; font-size: 2.5em; text-shadow: 2px 2px 4px rgba(0,0,0,0.2);'> | |
| {greeting}, {name}! 🌟 | |
| </h1> | |
| <p style='color: #666; font-style: italic;'> | |
| Current time: {current_time} | |
| </p> | |
| <div style='margin: 20px; padding: 15px; background: linear-gradient(45deg, #E8F8F5, #D4E6F1); border-radius: 10px; box-shadow: 0 4px 6px rgba(0,0,0,0.1);'> | |
| <p>Thank you for visiting! Have a wonderful day! ✨</p> | |
| </div> | |
| </div> | |
| <style> | |
| @keyframes fadeIn {{ | |
| from {{ opacity: 0; transform: translateY(-20px); }} | |
| to {{ opacity: 1; transform: translateY(0); }} | |
| }} | |
| </style> | |
| """ | |
| return message | |
| # Create the Gradio interface with a custom theme | |
| custom_css = """ | |
| .gradio-container { | |
| background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%); | |
| } | |
| """ | |
| with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo: | |
| gr.Markdown( | |
| """ | |
| # ✨ Fancy Hello World Generator ✨ | |
| Create beautiful personalized greetings in different languages! | |
| """ | |
| ) | |
| with gr.Row(): | |
| with gr.Column(): | |
| name_input = gr.Textbox( | |
| label="Enter your name", | |
| placeholder="Type your name here...", | |
| lines=1 | |
| ) | |
| language_input = gr.Dropdown( | |
| choices=["English", "Spanish", "French", "Japanese", "German", "Chinese"], | |
| label="Select Language", | |
| value="English" | |
| ) | |
| greet_btn = gr.Button("Generate Greeting!", variant="primary") | |
| with gr.Column(): | |
| output = gr.HTML(label="Your Fancy Greeting") | |
| greet_btn.click( | |
| fn=greet, | |
| inputs=[name_input, language_input], | |
| outputs=output | |
| ) | |
| gr.Markdown( | |
| """ | |
| ### 🌈 Features | |
| - Multiple language support | |
| - Real-time clock | |
| - Smooth animations | |
| - Beautiful gradient design | |
| """ | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() |