-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgui_v2.py
149 lines (129 loc) · 4.27 KB
/
gui_v2.py
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go
from dash.dependencies import Input, Output
import logging
log = logging.getLogger('werkzeug')
log.setLevel(logging.ERROR)
app = dash.Dash(__name__)
app.layout = html.Div(
html.Div([
html.H4('DinoAI'),
html.Div(id='live-update-text'),
dcc.Graph(id='live-graph',
style={
'height': '200px'
}),
dcc.Interval(
id='interval-component',
interval=0.1 * 1000, # in milliseconds
n_intervals=0
),
html.Div(
id='live-generations',
style={
'float': 'left',
'width': '80%'
}
),
html.Div(
id='live-network',
style={
'float': 'right',
'width': '20%'
}
),
html.Div(
id='live-logs',
style={
'width': '100%'
}
)
])
)
@app.callback(Output('live-update-text', 'children'),
[Input('interval-component', 'n_intervals')])
def update_metrics(n):
global score, size, speed, position, i_gen, i_generation, net_value, mode, net_mode, folder, n_genes, \
n_generation, ypos, logs
F = open("./tmp/dash_data.txt", "r")
datos = F.readlines()
F.close()
score = datos[0]
size = datos[1]
speed = datos[2]
position = datos[3]
i_gen = int(datos[4]) + 1
i_generation = datos[5]
net_value = datos[6]
mode = datos[7]
net_mode = datos[8]
folder = datos[9]
n_genes = datos[10]
n_generation = datos[11]
ypos = datos[12]
logs = datos[13]
style = {'padding': '5px', 'fontSize': '16px', 'font-family': 'Arial, Helvetica, sans-serif'}
return [
html.P(f'Score: {score}', style=style),
html.P(f'Size: {size}', style=style),
html.P(f'Speed: {speed}', style=style),
html.P(f'X position: {position}', style=style),
html.P(f'Y position: {ypos}', style = style)
]
@app.callback(Output('live-generations', 'children'),
[Input('interval-component', 'n_intervals')])
def update_generations(n):
global net_value, mode, net_mode, folder, logs
log_lines = logs.split("<br/>")
style = {'padding': '5px', 'fontSize': '16px', 'font-family': 'Arial, Helvetica, sans-serif'}
return [
html.P(f'Mode: {mode}', style=style),
html.P(f'Net value: {net_value}', style=style),
html.P(f'Net mode: {net_mode}', style=style),
html.P(f'Folder: {folder}', style=style)
]
@app.callback(Output('live-network', 'children'),
[Input('interval-component', 'n_intervals')])
def update_network(n):
global score, size, speed, position, i_gen, i_generation, n_generation, n_genes
style = {'padding': '5px', 'fontSize': '16px', 'font-family': 'Arial, Helvetica, sans-serif'}
return [
html.P(f'Generation: {i_generation}/{n_generation}', style=style),
html.P(f'Gen: {i_gen}/{n_genes}', style=style),
]
@app.callback(Output('live-logs', 'children'),
[Input('interval-component', 'n_intervals')])
def update_logs(n):
global logs
style = {'padding': '5px', 'fontSize': '16px', 'font-family': 'Arial, Helvetica, sans-serif', 'width': '100%'}
return [
html.Iframe(srcDoc=logs, style=style)
]
@app.callback(Output('live-graph', 'figure'),
[Input('interval-component', 'n_intervals')])
def update_graph(n):
global score, size, speed, position
score = float(score)
speed = float(speed)
position = float(position)
position_plot = position/500
score_plot = score / 10000
speed_plot = speed / 20
data = [go.Bar(
x=['Score', 'Speed', 'Position'],
y=[score_plot, speed_plot, position_plot],
x0=[0, 0, 0],
)]
layout = go.Layout(
yaxis=dict(
range=[0, 1],
ticks="",
visible=False
),
)
fig = go.Figure(data = data, layout=layout)
return fig
if __name__ == '__main__':
app.run_server(debug=True)