Spaces:
Sleeping
Sleeping
Update app.py via Space Creator
Browse files
app.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
|
| 3 |
+
def add(a, b):
|
| 4 |
+
return a + b
|
| 5 |
+
|
| 6 |
+
def multiply(a, b):
|
| 7 |
+
return a * b
|
| 8 |
+
|
| 9 |
+
def greet(name):
|
| 10 |
+
return f"Hello, {name}!"
|
| 11 |
+
|
| 12 |
+
demo = gr.Blocks()
|
| 13 |
+
|
| 14 |
+
with demo:
|
| 15 |
+
gr.Markdown("# Simple Calculator and Greeter")
|
| 16 |
+
gr.Markdown("This demo includes two simple functions: addition, multiplication, and a greeting.")
|
| 17 |
+
|
| 18 |
+
with gr.Tab("Addition"):
|
| 19 |
+
a = gr.Number(label="Number 1")
|
| 20 |
+
b = gr.Number(label="Number 2")
|
| 21 |
+
result = gr.Number(label="Result")
|
| 22 |
+
gr.Button("Add").click(add, inputs=[a, b], outputs=result)
|
| 23 |
+
|
| 24 |
+
with gr.Tab("Multiplication"):
|
| 25 |
+
a2 = gr.Number(label="Number 1")
|
| 26 |
+
b2 = gr.Number(label="Number 2")
|
| 27 |
+
result2 = gr.Number(label="Result")
|
| 28 |
+
gr.Button("Multiply").click(multiply, inputs=[a2, b2], outputs=result2)
|
| 29 |
+
|
| 30 |
+
with gr.Tab("Greeting"):
|
| 31 |
+
name = gr.Textbox(label="Your Name")
|
| 32 |
+
greeting = gr.Textbox(label="Greeting")
|
| 33 |
+
gr.Button("Greet").click(greet, inputs=[name], outputs=greeting)
|
| 34 |
+
|
| 35 |
+
if __name__ == "__main__":
|
| 36 |
+
demo.launch()
|