mirror of
https://github.com/gradio-app/gradio.git
synced 2024-12-21 02:19:59 +08:00
3bef9756fd
* 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>
26 lines
691 B
Python
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() |