2020-10-27 06:27:28 +08:00
|
|
|
import gradio as gr
|
2020-11-04 23:38:48 +08:00
|
|
|
import random
|
2020-10-27 06:27:28 +08:00
|
|
|
|
|
|
|
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,
|
|
|
|
["number", gr.inputs.Radio(["add", "subtract", "multiply", "divide"]), "number"],
|
|
|
|
"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-04-16 02:06:02 +08:00
|
|
|
title="test calculator"
|
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-01-21 00:47:46 +08:00
|
|
|
iface.launch()
|