import numpy as np import gradio as gr def mycalculator(in_num_a,in_num_b,method): if method == "add": return in_num_a + in_num_b if method == "minus": return in_num_a - in_num_b if method == "multiply": return in_num_a * in_num_b if method == "divide": if in_num_b!=0.0: return in_num_a/in_num_b else: return np.nan demo = gr.Interface( fn=mycalculator, inputs=[ gr.Number(precision=5,label="a"), gr.Number(precision=5,label="b"), gr.Radio(["add","minus","multiply","divide"]) ], outputs="number") demo.launch()