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