File size: 2,605 Bytes
9aed787
 
56ba131
9aed787
 
 
56ba131
 
9aed787
56ba131
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9aed787
 
 
 
 
56ba131
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9aed787
 
 
 
56ba131
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import gradio as gr

from src.utils import select_board

TITLE = """<h1 align="center" id="space-title"> Pento-LLaVA 🤖🎯🎮</h1>"""

pento_llava_app = gr.Blocks()
fig, targets, info = select_board('easy', 18, 0)

# Update the figure to include a boundary/frame
fig.update_layout(
    xaxis=dict(showline=True, linecolor='black', linewidth=2, showgrid=True, zeroline=True),
    yaxis=dict(showline=True, linecolor='black', linewidth=2, showgrid=True, zeroline=True),
    margin=dict(l=0, r=0, t=0, b=0),
    height=512,
    width=512
)

target_strs = []
for t in targets:
    target_strs.append(t['target_str'])

def gen_new_board(value):
    value = int(value)
    fig, _, _ = select_board('easy', 18, value)

    # Update the figure to include a boundary/frame
    fig.update_layout(
        xaxis=dict(showline=True, linecolor='black', linewidth=2, showgrid=True, zeroline=True),
        yaxis=dict(showline=True, linecolor='black', linewidth=2, showgrid=True, zeroline=True),
        margin=dict(l=0, r=0, t=0, b=0),
        height=512,
        width=512
    )

    return fig

def gen_info(value):
    value = int(value)
    _, _, info = select_board('easy', 18, value)

    return info

def gen_target_str(value):
    value = int(value)
    _, _, info = select_board('easy', 18, value)
    target_info = info[0]
    target_str = f"<span>Target piece for this episode is <span style='color: {target_info['piece_colour']};'>{target_info['piece_colour']}</span> <span style='color: {target_info['piece_colour']};'>{target_info['piece_shape']}</span> located at <span style='color: {target_info['piece_colour']};'>{target_info['piece_region']}</span></span>"

    return target_str


with pento_llava_app:

    gr.HTML(TITLE)

    with gr.Row():
        with gr.Column():    
            main_board = gr.Plot(fig)

        with gr.Column():
            with gr.Row():
                select_board_items = gr.Dropdown(
                    choices=range(512),
                    interactive=True
                )

            with gr.Row():
                 display_string = gr.HTML(value=gen_target_str(0)) 
        

            select_board_items.change(
                fn=gen_new_board,
                inputs=[select_board_items],
                outputs=[main_board],
                queue=True
            )

            select_board_items.change(
                fn=gen_target_str,
                inputs=[select_board_items],
                outputs=[display_string],
                queue=True
            )


    pento_llava_app.load()

pento_llava_app.queue()
pento_llava_app.launch()