Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,31 @@
|
|
1 |
import gradio as gr
|
2 |
|
3 |
-
|
4 |
-
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
|
3 |
+
# π§ Function to personalize the greeting
|
4 |
+
def greet(name, style, excitement_level):
|
5 |
+
base_greeting = {
|
6 |
+
"Friendly": "Hello",
|
7 |
+
"Formal": "Greetings",
|
8 |
+
"Casual": "Hey"
|
9 |
+
}[style]
|
10 |
|
11 |
+
return f"{base_greeting} {name}{'!' * excitement_level}"
|
12 |
+
|
13 |
+
# π¨ Custom theme (dark and sleek)
|
14 |
+
theme = gr.themes.Soft(primary_hue="teal", secondary_hue="blue")
|
15 |
+
|
16 |
+
# π§± Create a modern layout with Blocks
|
17 |
+
with gr.Blocks(theme=theme, title="Greeting Generator") as demo:
|
18 |
+
gr.Markdown("## π Personalized Greeting App\nFill the form below and get a custom greeting!")
|
19 |
+
|
20 |
+
with gr.Row():
|
21 |
+
name = gr.Textbox(label="Your Name", placeholder="Enter your name here", lines=1)
|
22 |
+
style = gr.Dropdown(choices=["Friendly", "Formal", "Casual"], value="Friendly", label="Greeting Style")
|
23 |
+
excitement = gr.Slider(minimum=1, maximum=5, step=1, value=2, label="Excitement Level (Number of !)")
|
24 |
+
|
25 |
+
greet_btn = gr.Button("Generate Greeting π")
|
26 |
+
output = gr.Textbox(label="Your Greeting", interactive=False)
|
27 |
+
|
28 |
+
greet_btn.click(fn=greet, inputs=[name, style, excitement], outputs=output)
|
29 |
+
|
30 |
+
# π Launch the app in browser
|
31 |
+
demo.launch(inbrowser=True)
|