File size: 735 Bytes
350c210
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import gradio as gr

def calculator(operation, a, b):
    if operation == "Add":
        return a + b
    elif operation == "Subtract":
        return a - b
    elif operation == "Multiply":
        return a * b
    elif operation == "Divide":
        if b == 0:
            return "Cannot divide by zero"
        return a / b
    else:
        return "Invalid operation"

demo = gr.Interface(
    fn=calculator,
    inputs=[
        gr.Radio(["Add", "Subtract", "Multiply", "Divide"], label="Operation"),
        gr.Number(label="Input A"),
        gr.Number(label="Input B")
    ],
    outputs="text",
    title="Demo Calculator",
    description="Perform basic arithmetic operations."
)

if __name__ == "__main__":
    demo.launch()