Spaces:
Runtime error
Runtime error
Upload folder using huggingface_hub
Browse files- app.py +140 -0
- requirements.txt +10 -0
app.py
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import time
|
| 3 |
+
|
| 4 |
+
def greet(name, greeting_style, emoji_enabled):
|
| 5 |
+
"""Generate a personalized greeting based on user input."""
|
| 6 |
+
if not name.strip():
|
| 7 |
+
return "Please enter your name!"
|
| 8 |
+
|
| 9 |
+
greetings = {
|
| 10 |
+
"Formal": f"Good day, {name}! It's a pleasure to meet you.",
|
| 11 |
+
"Casual": f"Hey {name}! What's up?",
|
| 12 |
+
"Friendly": f"Hello there, {name}! Great to see you!",
|
| 13 |
+
"Professional": f"Dear {name}, welcome to our application.",
|
| 14 |
+
"Enthusiastic": f"Wow, {name}! So excited to have you here!"
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
base_greeting = greetings.get(greeting_style, f"Hello, {name}!")
|
| 18 |
+
|
| 19 |
+
if emoji_enabled:
|
| 20 |
+
emojis = ["π", "π", "π", "β¨", "π", "π«"]
|
| 21 |
+
emoji = time.time() % len(emojis)
|
| 22 |
+
base_greeting += f" {emojis[int(emoji)]}"
|
| 23 |
+
|
| 24 |
+
return base_greeting
|
| 25 |
+
|
| 26 |
+
def get_current_time():
|
| 27 |
+
"""Get current time for display."""
|
| 28 |
+
return time.strftime("%H:%M:%S")
|
| 29 |
+
|
| 30 |
+
# Create the Gradio 6 application
|
| 31 |
+
with gr.Blocks(
|
| 32 |
+
title="Greeting App",
|
| 33 |
+
theme=gr.themes.Soft(),
|
| 34 |
+
footer_links=[
|
| 35 |
+
{"label": "Built with anycoder", "url": "https://huggingface.co/spaces/akhaliq/anycoder"}
|
| 36 |
+
]
|
| 37 |
+
) as demo:
|
| 38 |
+
|
| 39 |
+
# Header with branding
|
| 40 |
+
gr.HTML("""
|
| 41 |
+
<div style="text-align: center; margin-bottom: 20px;">
|
| 42 |
+
<h1>π Welcome to the Greeting App!</h1>
|
| 43 |
+
<p style="color: #666;">Create personalized greetings with different styles</p>
|
| 44 |
+
<p><a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" style="color: #007bff; text-decoration: underline;">Built with anycoder</a></p>
|
| 45 |
+
</div>
|
| 46 |
+
""")
|
| 47 |
+
|
| 48 |
+
with gr.Row():
|
| 49 |
+
with gr.Column(scale=2):
|
| 50 |
+
# Input section
|
| 51 |
+
name_input = gr.Textbox(
|
| 52 |
+
label="Your Name",
|
| 53 |
+
placeholder="Enter your name here...",
|
| 54 |
+
autofocus=True,
|
| 55 |
+
lines=1
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
style_radio = gr.Radio(
|
| 59 |
+
choices=["Formal", "Casual", "Friendly", "Professional", "Enthusiastic"],
|
| 60 |
+
value="Friendly",
|
| 61 |
+
label="Greeting Style",
|
| 62 |
+
info="Choose how you'd like to be greeted"
|
| 63 |
+
)
|
| 64 |
+
|
| 65 |
+
emoji_checkbox = gr.Checkbox(
|
| 66 |
+
label="Add Emoji",
|
| 67 |
+
value=True,
|
| 68 |
+
info="Include a fun emoji with your greeting"
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
# Buttons
|
| 72 |
+
with gr.Row():
|
| 73 |
+
greet_btn = gr.Button("Generate Greeting", variant="primary", size="lg")
|
| 74 |
+
clear_btn = gr.Button("Clear", variant="secondary")
|
| 75 |
+
|
| 76 |
+
with gr.Column(scale=3):
|
| 77 |
+
# Output section
|
| 78 |
+
output_text = gr.Textbox(
|
| 79 |
+
label="Your Personalized Greeting",
|
| 80 |
+
lines=3,
|
| 81 |
+
interactive=False,
|
| 82 |
+
show_copy_button=True
|
| 83 |
+
)
|
| 84 |
+
|
| 85 |
+
# Current time display
|
| 86 |
+
time_display = gr.Textbox(
|
| 87 |
+
label="Current Time",
|
| 88 |
+
value=get_current_time(),
|
| 89 |
+
interactive=False,
|
| 90 |
+
every=1
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
# Example section
|
| 94 |
+
gr.Examples(
|
| 95 |
+
examples=[
|
| 96 |
+
["Alice", "Casual", True],
|
| 97 |
+
["Bob", "Professional", False],
|
| 98 |
+
["Charlie", "Enthusiastic", True],
|
| 99 |
+
["Diana", "Formal", False]
|
| 100 |
+
],
|
| 101 |
+
inputs=[name_input, style_radio, emoji_checkbox],
|
| 102 |
+
label="Try these examples:",
|
| 103 |
+
examples_per_page=4
|
| 104 |
+
)
|
| 105 |
+
|
| 106 |
+
# Event listeners with Gradio 6 syntax
|
| 107 |
+
greet_btn.click(
|
| 108 |
+
fn=greet,
|
| 109 |
+
inputs=[name_input, style_radio, emoji_checkbox],
|
| 110 |
+
outputs=output_text,
|
| 111 |
+
api_visibility="public"
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
# Also trigger on Enter key for name input
|
| 115 |
+
name_input.submit(
|
| 116 |
+
fn=greet,
|
| 117 |
+
inputs=[name_input, style_radio, emoji_checkbox],
|
| 118 |
+
outputs=output_text,
|
| 119 |
+
api_visibility="public"
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
# Clear button functionality
|
| 123 |
+
clear_btn.click(
|
| 124 |
+
fn=lambda: ["", "Friendly", True, ""],
|
| 125 |
+
outputs=[name_input, style_radio, emoji_checkbox, output_text],
|
| 126 |
+
api_visibility="private"
|
| 127 |
+
)
|
| 128 |
+
|
| 129 |
+
# Footer info
|
| 130 |
+
gr.HTML("""
|
| 131 |
+
<div style="text-align: center; margin-top: 30px; padding-top: 20px; border-top: 1px solid #eee;">
|
| 132 |
+
<p style="color: #888; font-size: 0.9em;">
|
| 133 |
+
π‘ Tip: Try different greeting styles and toggle emojis for fun variations!
|
| 134 |
+
</p>
|
| 135 |
+
</div>
|
| 136 |
+
""")
|
| 137 |
+
|
| 138 |
+
# Launch the application
|
| 139 |
+
if __name__ == "__main__":
|
| 140 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
requests
|
| 3 |
+
Pillow
|
| 4 |
+
numpy
|
| 5 |
+
pandas
|
| 6 |
+
matplotlib
|
| 7 |
+
plotly
|
| 8 |
+
fastapi
|
| 9 |
+
uvicorn
|
| 10 |
+
pydantic
|