2020-10-27 06:27:28 +08:00
|
|
|
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
|
|
|
|
|
|
|
|
iface = gr.Interface(calculator,
|
2021-05-24 14:53:30 +08:00
|
|
|
["number", gr.inputs.Radio(["add", "subtract", "multiply", "divide"]), "number"],
|
2020-10-27 06:27:28 +08:00
|
|
|
"number",
|
|
|
|
examples=[
|
2020-11-05 04:16:10 +08:00
|
|
|
[5, "add", 3],
|
|
|
|
[4, "divide", 2],
|
|
|
|
[-4, "multiply", 2.5],
|
|
|
|
[0, "subtract", 1.2],
|
2021-01-30 02:23:17 +08:00
|
|
|
],
|
2021-05-24 23:31:44 +08:00
|
|
|
title="test calculator",
|
2021-06-18 04:04:22 +08:00
|
|
|
description="heres a sample toy calculator. enjoy!",
|
2021-08-17 05:58:30 +08:00
|
|
|
flagging_options=["this", "or", "that"],
|
2020-10-27 06:27:28 +08:00
|
|
|
)
|
2020-11-11 22:15:53 +08:00
|
|
|
|
2020-10-27 06:27:28 +08:00
|
|
|
if __name__ == "__main__":
|
2021-08-18 04:42:07 +08:00
|
|
|
iface.launch()
|