Spaces:
Sleeping
Sleeping
File size: 1,828 Bytes
581fe3f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 | """Pure Gradio Hello World App"""
import gradio as gr
def greet(name: str, enthusiasm: int = 1) -> str:
"""Generate a greeting message.
Args:
name: The name to greet
enthusiasm: Number of exclamation marks (1-5)
Returns:
A personalized greeting
"""
if not name:
return "Please enter a name!"
exclamation = "!" * min(max(enthusiasm, 1), 5)
return f"Hello, {name}{exclamation} Welcome to the Gradio + FastAPI demo!"
# Pure Gradio app - can run standalone or be mounted to FastAPI
with gr.Blocks(title="Hello World Demo") as app:
gr.Markdown("# 👋 Hello World App")
gr.Markdown("Enter your name and choose your enthusiasm level!")
with gr.Row():
with gr.Column():
name_input = gr.Textbox(
label="Your Name",
placeholder="Enter your name here...",
value="World"
)
enthusiasm_slider = gr.Slider(
minimum=1,
maximum=5,
value=1,
step=1,
label="Enthusiasm Level"
)
greet_btn = gr.Button("Greet Me!", variant="primary")
with gr.Column():
output = gr.Textbox(
label="Greeting",
interactive=False
)
greet_btn.click(
fn=greet,
inputs=[name_input, enthusiasm_slider],
outputs=output
)
gr.Examples(
examples=[
["Alice", 3],
["Bob", 1],
["Charlie", 5],
],
inputs=[name_input, enthusiasm_slider],
)
# This allows the app to run standalone
if __name__ == "__main__":
app.launch(
server_name="0.0.0.0",
server_port=7860,
share=False
)
|