gradio/demo/calculator.py
aliabid94 3bef9756fd
Allow for bulk input from examples (#74)
* bulk input first commit

* add titanic demo support

* remove flagged content

* route vendor files through gradio.app if share=True; cache bust other static files

* s

* navigate examples with arrow keys

* navigate examples with arrow keys

* navigate examples with arrow keys

Co-authored-by: Ali Abid <aliabid94@gmail.com>
2020-11-04 07:38:48 -08:00

26 lines
691 B
Python

import gradio as gr
import random
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=[
[
random.randint(1, 10),
random.choice(["add", "subtract", "multiply", "divide"]),
random.randint(1, 5),
] for _ in range(10)
]
)
if __name__ == "__main__":
iface.launch()