File size: 736 Bytes
686adb8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 calculate(operation, num1, num2):
  try:
    num1 = int(num1)
    num2 = int(num2)
  except ValueError:
    return "Invalid input"

  if operation == 'Add':
    return num1 + num2
  elif operation == 'Subtract':
    return num1 - num2
  elif operation == 'Multiply':
    return num1 * num2
  elif operation == 'Divide':
    return num1 / num2
  else:
    return 'Invalid operation'

operation_input = gr.inputs.Radio(["Add", "Subtract", "Multiply", "Divide"], default="Add")
num1_input = gr.inputs.Textbox(label="Enter first number")
num2_input = gr.inputs.Textbox(label="Enter second number")

gr.Interface(
  calculate,
  [operation_input, num1_input, num2_input],
  gr.outputs.Textbox()
).launch(debug=True)