import gradio as gr def calculator(num1, num2, operation): if operation == '+': return num1 + num2 elif operation == '-': return num1 - num2 elif operation == '*': return num1 * num2 elif operation == '/': if num2 == 0: return "除數不能為零" return num1 / num2 else: return "無效運算符號" demo = gr.Interface( fn=calculator, inputs=[ gr.Number(label="數字1"), gr.Number(label="數字2"), gr.Dropdown(["+", "-", "*", "/"], label="運算符號") ], outputs=gr.Textbox(label="結果"), title="簡易計算機", description="輸入兩個數字和運算符號,計算結果", allow_flagging='never', examples=[ [45, 3, "-"], [3.14, 2, "/"], [144, 2.5, "*"], [1, 1.2, "+"], ], ) demo.launch()