File size: 875 Bytes
f983a75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
31
32
33
import gradio as gr
import numpy as np


# Goal: Maximize
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()