|
import gradio as gr |
|
import numpy as np |
|
|
|
|
|
|
|
def lookup(x, y, z): |
|
y = ( |
|
(z == 1) * np.sin(x) * (1 + np.sin(y)) |
|
+ (z == 2) * (x * np.sin(0.9 * x) + np.sin(x) * np.sin(y)) |
|
+ (z == 3) * (np.sqrt(x + 8) * np.sin(x) + np.sin(x) * np.sin(y)) |
|
+ (z == 4) * (x * np.sin(1.666 * np.sqrt(x + 8)) + np.sin(x) * np.sin(y)) |
|
) |
|
|
|
return y |
|
|
|
|
|
defaults = (0.5, -0.3, 1.0) |
|
|
|
iface = gr.Interface( |
|
fn=lookup, |
|
inputs=[ |
|
gr.Slider( |
|
minimum=-2.0 * np.pi, maximum=2.0 * np.pi, value=defaults[0], label="x" |
|
), |
|
gr.Slider( |
|
minimum=-2.0 * np.pi, maximum=2.0 * np.pi, value=defaults[1], label="y" |
|
), |
|
gr.Radio(choices=[1.0, 2.0, 3.0, 4.0], value=defaults[2], label="z"), |
|
], |
|
outputs=gr.Number(lookup(*defaults), label="example function value (maximize)"), |
|
) |
|
iface.launch() |
|
|