File size: 732 Bytes
fee9ecd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3d5f1e5
 
fee9ecd
 
 
 
 
 
 
 
 
 
 
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import gradio as gr
import numpy as np


# Goal: Minimize
def process(
    x1,
    x2,
    x3,
    x4,
    x5,
    x6,
    x7,
    x8,
    x9,
    x10,
    x11,
    x12,
    x13,
    x14,
    x15,
    x16,
    x17,
    x18,
    x19,
    x20,
):
    y = (
        (x1 - 2) ** 2
        + 0.8 * x3
        + 0.4 * (x6 + 1) ** 2
        + (x12) ** 2
        - 0.3 * (x18 - 2) ** 2
        + x1 * x6
    )

    return y

#
    
defaults = np.random.uniform(0, 1, 20)

iface = gr.Interface(
    fn=process,
    inputs=[
        gr.Slider(minimum=0.0, maximum=1.0, value=defaults[k], label=f"x{k+1}")
        for k in range(20)
    ],
    outputs=gr.Number(process(*defaults), label="process function value (minimize)"),
)
iface.launch()