Spaces:
Sleeping
Sleeping
lei lei
commited on
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import time
|
| 3 |
+
from datetime import datetime
|
| 4 |
+
|
| 5 |
+
def greet(name, language):
|
| 6 |
+
if not name:
|
| 7 |
+
name = "World"
|
| 8 |
+
|
| 9 |
+
greetings = {
|
| 10 |
+
"English": "Hello",
|
| 11 |
+
"Spanish": "¡Hola",
|
| 12 |
+
"French": "Bonjour",
|
| 13 |
+
"Japanese": "こんにちは",
|
| 14 |
+
"German": "Hallo"
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
# Get current time
|
| 18 |
+
current_time = datetime.now().strftime("%H:%M:%S")
|
| 19 |
+
|
| 20 |
+
# Add a small delay for animation effect
|
| 21 |
+
time.sleep(0.5)
|
| 22 |
+
|
| 23 |
+
greeting = greetings.get(language, "Hello")
|
| 24 |
+
message = f"""
|
| 25 |
+
<div style='text-align: center; animation: fadeIn 1s;'>
|
| 26 |
+
<h1 style='color: #2E86C1; font-size: 2.5em; text-shadow: 2px 2px 4px rgba(0,0,0,0.2);'>
|
| 27 |
+
{greeting}, {name}! 🌟
|
| 28 |
+
</h1>
|
| 29 |
+
<p style='color: #666; font-style: italic;'>
|
| 30 |
+
Current time: {current_time}
|
| 31 |
+
</p>
|
| 32 |
+
<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);'>
|
| 33 |
+
<p>Thank you for visiting! Have a wonderful day! ✨</p>
|
| 34 |
+
</div>
|
| 35 |
+
</div>
|
| 36 |
+
|
| 37 |
+
<style>
|
| 38 |
+
@keyframes fadeIn {{
|
| 39 |
+
from {{ opacity: 0; transform: translateY(-20px); }}
|
| 40 |
+
to {{ opacity: 1; transform: translateY(0); }}
|
| 41 |
+
}}
|
| 42 |
+
</style>
|
| 43 |
+
"""
|
| 44 |
+
return message
|
| 45 |
+
|
| 46 |
+
# Create the Gradio interface with a custom theme
|
| 47 |
+
custom_css = """
|
| 48 |
+
.gradio-container {
|
| 49 |
+
background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
|
| 50 |
+
}
|
| 51 |
+
"""
|
| 52 |
+
|
| 53 |
+
with gr.Blocks(css=custom_css, theme=gr.themes.Soft()) as demo:
|
| 54 |
+
gr.Markdown(
|
| 55 |
+
"""
|
| 56 |
+
# ✨ Fancy Hello World Generator ✨
|
| 57 |
+
Create beautiful personalized greetings in different languages!
|
| 58 |
+
"""
|
| 59 |
+
)
|
| 60 |
+
|
| 61 |
+
with gr.Row():
|
| 62 |
+
with gr.Column():
|
| 63 |
+
name_input = gr.Textbox(
|
| 64 |
+
label="Enter your name",
|
| 65 |
+
placeholder="Type your name here...",
|
| 66 |
+
lines=1
|
| 67 |
+
)
|
| 68 |
+
language_input = gr.Dropdown(
|
| 69 |
+
choices=["English", "Spanish", "French", "Japanese", "German"],
|
| 70 |
+
label="Select Language",
|
| 71 |
+
value="English"
|
| 72 |
+
)
|
| 73 |
+
greet_btn = gr.Button("Generate Greeting!", variant="primary")
|
| 74 |
+
|
| 75 |
+
with gr.Column():
|
| 76 |
+
output = gr.HTML(label="Your Fancy Greeting")
|
| 77 |
+
|
| 78 |
+
greet_btn.click(
|
| 79 |
+
fn=greet,
|
| 80 |
+
inputs=[name_input, language_input],
|
| 81 |
+
outputs=output
|
| 82 |
+
)
|
| 83 |
+
|
| 84 |
+
gr.Markdown(
|
| 85 |
+
"""
|
| 86 |
+
### 🌈 Features
|
| 87 |
+
- Multiple language support
|
| 88 |
+
- Real-time clock
|
| 89 |
+
- Smooth animations
|
| 90 |
+
- Beautiful gradient design
|
| 91 |
+
"""
|
| 92 |
+
)
|
| 93 |
+
|
| 94 |
+
if __name__ == "__main__":
|
| 95 |
+
demo.launch()
|