Spaces:
Sleeping
Sleeping
| """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 | |
| ) | |