ReconViaGen / app.py
Stable-X's picture
Update app.py from anycoder
eb16685 verified
import gradio as gr
def greet(name: str, enthusiasm: int = 1) -> str:
"""
Enhanced greeting function with customizable enthusiasm.
"""
if not name.strip():
return "Please enter a name!"
greeting = f"Hello, {name}!"
exclamation = "!" * enthusiasm
return f"{greeting}{exclamation} Welcome to your Gradio 6 application."
# Version 1: Enhanced with Examples and Validation
with gr.Blocks() as demo:
gr.HTML(
"""
<div style="text-align: center; margin-bottom: 20px;">
<a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" style="text-decoration: none; color: #007bff; font-weight: bold;">
Built with anycoder
</a>
</div>
"""
)
gr.Markdown("# 🚀 Enhanced Gradio 6 App")
gr.Markdown("Enter your name and choose enthusiasm level for a personalized greeting.")
with gr.Row():
with gr.Column():
name_input = gr.Textbox(
label="Your Name",
placeholder="Type your name here...",
autofocus=True,
max_length=50
)
enthusiasm_slider = gr.Slider(
label="Enthusiasm Level",
minimum=1,
maximum=5,
value=1,
step=1,
info="How excited should the greeting be?"
)
submit_btn = gr.Button("Generate Greeting", variant="primary", size="lg")
# Add examples
examples = gr.Examples(
examples=[
["Alice", 3],
["Bob", 1],
["Charlie", 5]
],
inputs=[name_input, enthusiasm_slider],
label="Quick Examples"
)
with gr.Column():
greeting_output = gr.Textbox(
label="Output",
interactive=False,
lines=2,
show_copy_button=True
)
# Add a stats component
char_count = gr.Number(label="Character Count", interactive=False)
# Event listeners with Gradio 6 syntax
def process_greeting(name, enthusiasm):
result = greet(name, enthusiasm)
return result, len(result)
submit_btn.click(
fn=process_greeting,
inputs=[name_input, enthusiasm_slider],
outputs=[greeting_output, char_count],
api_visibility="public"
)
# Real-time updates
name_input.change(
fn=process_greeting,
inputs=[name_input, enthusiasm_slider],
outputs=[greeting_output, char_count],
api_visibility="private"
)
enthusiasm_slider.change(
fn=process_greeting,
inputs=[name_input, enthusiasm_slider],
outputs=[greeting_output, char_count],
api_visibility="private"
)
demo.launch(
theme=gr.themes.Soft(
primary_hue="blue",
secondary_hue="cyan",
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"
),
footer_links=[
{"label": "Gradio", "url": "https://gradio.app"},
{"label": "GitHub", "url": "https://github.com/gradio-app/gradio"}
],
show_error=True
)