mirror of
https://github.com/gradio-app/gradio.git
synced 2024-12-21 02:19:59 +08:00
9b42ba8f10
* changes * changes * revert changes * changes * add changeset * notebooks script * changes * changes --------- Co-authored-by: Ali Abid <aliabid94@gmail.com> Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com> Co-authored-by: Ali Abdalla <ali.si3luwa@gmail.com>
38 lines
1.0 KiB
Python
38 lines
1.0 KiB
Python
import gradio as gr
|
|
|
|
def calculator(num1, operation, num2):
|
|
if operation == "add":
|
|
return num1 + num2
|
|
elif operation == "subtract":
|
|
return num1 - num2
|
|
elif operation == "multiply":
|
|
return num1 * num2
|
|
elif operation == "divide":
|
|
return num1 / num2
|
|
|
|
with gr.Blocks() as demo:
|
|
with gr.Row():
|
|
with gr.Column():
|
|
num_1 = gr.Number(value=4)
|
|
operation = gr.Radio(["add", "subtract", "multiply", "divide"])
|
|
num_2 = gr.Number(value=0)
|
|
submit_btn = gr.Button(value="Calculate")
|
|
with gr.Column():
|
|
result = gr.Number()
|
|
|
|
submit_btn.click(
|
|
calculator, inputs=[num_1, operation, num_2], outputs=[result], api_name=False
|
|
)
|
|
examples = gr.Examples(
|
|
examples=[
|
|
[5, "add", 3],
|
|
[4, "divide", 2],
|
|
[-4, "multiply", 2.5],
|
|
[0, "subtract", 1.2],
|
|
],
|
|
inputs=[num_1, operation, num_2],
|
|
)
|
|
|
|
if __name__ == "__main__":
|
|
demo.launch(show_api=False)
|